使用TCP客户端C#将数据发送到浏览器 [英] Send Data To Browser With TCP Client C#

查看:294
本文介绍了使用TCP客户端C#将数据发送到浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时将HTML文本发送到浏览器并且其他时间不起作用

即代码:



 静态  void  Main( string  [] args)
{
TcpListener les = new TcpListener(IPAddress.Parse( 127.0.0.1), 443 );
les.Start();
while true
{
Console.WriteLine(< span class =code-string> Waiting Connection .... + les.Server.LocalEndPoint);
TcpClient tcp = les.AcceptTcpClient();
线程A = new 线程( new ParameterizedThreadStart(TransmatingWithThreading));
A.Start(( object )tcp);
Thread.Sleep( 1000 );
}


}





请将任何身体费用退回给我

非常感谢

解决方案





我想你''重新尝试创建本地Web服务器。在这种情况下,我建议使用 System.Net.HttpListener [< a href =http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspxtarget =_ blanktitle =New Window> ^ ]而不是 TcpListener

还要看看我的提示:

用C#创建本地服务器 [ ^ ]



希望这会有所帮助。

Sometime sending HTML text to the browser and the nother time not working
that is the code :

static void Main(string[] args)
       {
           TcpListener les = new TcpListener(IPAddress.Parse("127.0.0.1"), 443);
           les.Start();
           while (true)
           {
               Console.WriteLine("Waiting Connection...." + les.Server.LocalEndPoint);
               TcpClient tcp = les.AcceptTcpClient();
               Thread A = new Thread(new ParameterizedThreadStart(TransmatingWithThreading));
               A.Start((object)tcp);
               Thread.Sleep(1000);
           }


       }



Please any body feesback me
Thanks alot

解决方案

Hi,

I think you''re trying to create a local web server. In that case, I recommend to use a System.Net.HttpListener[^] instead of a TcpListener.
Have also a look at my Tip:
Create a local server in C#[^]

Hope this helps.


这篇关于使用TCP客户端C#将数据发送到浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆