| | |
| | | |
| | | try |
| | | { |
| | | HttpSvcHost = new System.Net.HttpListener(); |
| | | HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous; |
| | | HttpSvcHost.Prefixes.Add("http://10.221.55.117:8808/"); |
| | | HttpSvcHost.Start(); |
| | | HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); |
| | | //HttpSvcHost = new System.Net.HttpListener(); |
| | | //HttpSvcHost.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous; |
| | | //HttpSvcHost.Prefixes.Add("http://10.221.55.117:8808/"); |
| | | //HttpSvcHost.Start(); |
| | | //HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | try |
| | | { |
| | | #region [èæ¬][20250605212104026][ä¸å¡é»è¾.SocketServer] |
| | | var host = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName()); |
| | | foreach (var ip in host.AddressList) |
| | | { |
| | | if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) |
| | | { |
| | | Console.WriteLine($"ip= {ip.ToString()}"); |
| | | new TcpServer(ip.ToString()); |
| | | } |
| | | } |
| | | AutoThread.InvokeMethod(AutoThread.Instance, "TaskEverythingRun"); |
| | | #endregion [èæ¬][20250605212104026][ä¸å¡é»è¾.SocketServer] |
| | | } |
| | | catch (Exception ex) |
| | |
| | | } |
| | | ExitJudgeStack.TryPop(out int exitJudgeVal); |
| | | }); |
| | | |
| | | /// <summary> |
| | | /// ç¨åºç段:Program1 |
| | | /// æè¿°: |
| | |
| | | #endregion |
| | | |
| | | #region Httpæå¡çå¬ |
| | | private void HttpSvcListenerCallback(IAsyncResult ar) |
| | | private async void HttpSvcListenerCallback(IAsyncResult ar) |
| | | { |
| | | System.Net.HttpListenerContext context = null; |
| | | try |
| | | { |
| | | HttpSvcHost.BeginGetContext(HttpSvcListenerCallback, null); |
| | | System.Net.HttpListenerContext context = HttpSvcHost.EndGetContext(ar); |
| | | context = HttpSvcHost.EndGetContext(ar); |
| | | System.Net.HttpListenerRequest request = context.Request; |
| | | System.Net.HttpListenerResponse response = context.Response; |
| | | switch (request.LocalEndPoint.ToString()) |
| | |
| | | using (var reader = new System.IO.StreamReader(request.InputStream, System.Text.Encoding.UTF8)) |
| | | { |
| | | string requestJson = reader.ReadToEnd(); |
| | | |
| | | string respstr = HttpSvcListenerCallback_he(request.HttpMethod, request.Url.AbsolutePath, requestJson, out System.Net.HttpStatusCode statusCode); |
| | | |
| | | System.Net.HttpStatusCode statusCode = 0; |
| | | string respstr = await Task.Run(() => |
| | | { |
| | | return HttpSvcListenerCallback_he(request.HttpMethod, request.Url.AbsolutePath, requestJson, out statusCode); |
| | | }); |
| | | string logContent = ""; |
| | | logContent += $"\r\n[{request.HttpMethod}]{request.Url.AbsolutePath}"; |
| | | logContent += $"\r\n[request]{requestJson}"; |
| | | logContent += $"\r\n[response]{respstr}"; |
| | | Conn.é»è®¤æ¥å¿?.Info(logContent); |
| | | _ = Task.Run(() => |
| | | { |
| | | Conn.é»è®¤æ¥å¿?.Info(logContent); |
| | | }); |
| | | |
| | | byte[] bytstr = Encoding.UTF8.GetBytes(respstr); |
| | | response.StatusCode = (int)statusCode; |
| | | response.SendChunked = false; |
| | | response.ContentLength64 = bytstr.Length; |
| | | response.OutputStream.Write(bytstr, 0, bytstr.Length); |
| | | response.Close(); |
| | | // 弿¥åå
¥ååº |
| | | await response.OutputStream.WriteAsync(bytstr, 0, bytstr.Length); |
| | | |
| | | } |
| | | break; |
| | | } |
| | |
| | | catch (Exception ex) |
| | | { |
| | | Conn.é»è®¤æ¥å¿.Error(ex.ToString()); |
| | | } |
| | | finally |
| | | { |
| | | context?.Response.Close(); |
| | | } |
| | | } |
| | | private System.String HttpSvcListenerCallback_he(System.String method, System.String path, System.String requestJson, out System.Net.HttpStatusCode statusCode) |
| | |
| | | { |
| | | switch (path) |
| | | { |
| | | case "/inddddddddddddddddd": |
| | | case var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase): |
| | | { |
| | | statusCode = System.Net.HttpStatusCode.OK; |
| | | // å¤å¶å°case ä¸ |
| | | //var _ when System.Text.RegularExpressions.Regex.IsMatch(path, @"\.(html|ico|js|css)(\?.*)?$", System.Text.RegularExpressions.RegexOptions.IgnoreCase) |
| | | var filePath = System.IO.Path.Combine("Static", path.Substring(1)); |
| | | var filePath = /*Directory.GetCurrentDirectory() + "\\Static" + "\\" + path.Substring(1);*/System.IO.Path.Combine(Directory.GetCurrentDirectory() + "\\Static", path.Substring(1)); |
| | | return File.ReadAllText(filePath); |
| | | } |
| | | } |