问题描述
publicForm1(){InitializeComponent();System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls=false;intport=6678;listener=newTcpListener(port);listener.Start();Threadthread=newThread(newThreadStart(reControlCode));thread.Start();}privatevoidreControlCode(){try{//设置接收套接字,接收listener.AcceptSocket是返回已经接收的客户的请求socket=listener.AcceptSocket();while(socket.Connected){stringstr="";stringss="";byte[]recvBytes=newbyte[1024];intbytes=0;while(true){bytes=socket.Receive(recvBytes,recvBytes.Length,0);if(bytes<=0)break;ss+=Encoding.ASCII.GetString(recvBytes,0,bytes);}switch(ss){case"openstar":str="true";SendMessage(str);break;default:break;}}}catch{}}
这个数据读完之后运行到bytes=socket.Receive(recvBytes,recvBytes.Length,0);就跳出去了,大家帮我解决一下,谢谢啊
时间: 2025-01-07 16:31:56