服务器和客户第一条消息 [英] server & client first message
本文介绍了服务器和客户第一条消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我有服务器会在客户端第一次连接到服务器时从客户端接收消息
但是客户端可能不会将消息发送到服务器
我该如何处理如何使服务器决定它是否接收来自客户端的消息"?
这是代码
和"if语句"
中的问题
我应该在if语句中写什么?????
hello
I have server will receive message from client at first time the client connect to the server
but may the client not send the message to the server
how can I handling this " how can I make the server decide if it receive or not receive message from client " ?
this is the code
and the problem in " if statement "
what should I write in the if statement ?????
IPAddress localAddr = IPAddress.Parse("127.0.0.1");
TcpSer = new TcpListener(localAddr, Int32.Parse(Port.Text));
TcpSer.Start();
// Keep on accepting Client Connection
while (true)
{
if (/* received message */ )
{
Thread rsvmsg =new Thread(new parameterizedThreadStart(RsvMsg));
// New Client connected, call Event to handle it.
Thread t = new Thread(new ParameterizedThreadStart(NewClient));
TcpCli = TcpSer.AcceptTcpClient();
rsvmsg.Start(TcpCli);
t.Start(TcpCli);
}
else
{
// New Client connected, call Event to handle it.
Thread t = new Thread(new ParameterizedThreadStart(NewClient));
TcpCli = TcpSer.AcceptTcpClient();
t.Start(TcpCli);
}
在此先感谢
thanks in advance
推荐答案
这个项目是一个很好的例子
多线程聊天服务器 [
this project is a good sample
Multithreaded Chat Server[^]
这篇关于服务器和客户第一条消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文