C#でHTTPプロトコルを用いて簡易サーバを作成しようと思ったのですが、
localhostでのアクセスはうまくいくのですが、グローバルIPアドレスを用いてアクセスしようとすると接続してくれません。
コマンドプロンプトで
netsh http add url urlacl url=http://+:90/ user=everyone
と予約して、
ファイアーウォールで新しい規則からTCPの90ポートをこじ開けました。
外部からのアクセスができるようにするためには後どのような手順が必要ですか?
OSはWindows10
サーバーサイドのプログラムは
C#
1using System; 2using System.Threading.Tasks; 3using System.Net; 4using System.IO; 5 6namespace HttpListener 7{ 8 //起動は出力して管理者として実行 9 class Program 10 { 11 public static string root = @"C:\www"; 12 public static void Process(HttpListenerContext context) 13 { 14 HttpListenerRequest req = context.Request; 15 HttpListenerResponse res = context.Response; 16 // リクエストされたURLからファイルのパスを求める 17 string path = root + req.RawUrl.Replace("/", "\\"); 18 // ファイルが存在すればレスポンス・ストリームに書き出す 19 if (File.Exists(path)) 20 { 21 byte[] content = File.ReadAllBytes(path); 22 res.OutputStream.Write(content, 0, content.Length); 23 } 24 res.Close(); 25 } 26 27 static void Main(string[] args) 28 { 29 var listener = new System.Net.HttpListener(); 30 listener.Prefixes.Add("http://*:90/"); 31 listener.Start(); 32 while (true) 33 { 34 HttpListenerContext context = listener.GetContext(); 35 Task.Run(() => Process(context)); 36 } 37 } 38 39 } 40}
追記
プロバイダはKDDIです。
ハード関係にはあまり詳しくないので、何の記述が必要か具体的にお願いします。
もう少しネットインフラについて勉強してからにします。すいませんでした。
回答6件
あなたの回答
tips
プレビュー