[英]What's the best way to check the first message that's received by the server?
With my tpc server i'm trying to get the first message that's sent by the client.使用我的 tpc 服务器,我试图获取客户端发送的第一条消息。 So that the server can determine what the purpose of the data is.
以便服务器可以确定数据的目的是什么。 Since the server can do multiple things with the data that gets sent from the clients.
由于服务器可以对从客户端发送的数据执行多种操作。 I was thinking maybe like a Protocol or something basically so that the server knows what the client wants to do.
我在想可能像协议或其他东西,以便服务器知道客户端想要做什么。
public enum Protocol
{
Chat;
Login;
Disconnect;
}
I made a Protocol class but i'm sure how I could integrate this with the streamRead.我创建了一个协议类,但我确定如何将它与流读取集成。
//Client
var c = Protocol.Chat;
stream.WriteByte((byte)c);
//Server
var header = (Protocol)stream.ReadByte();
switch (header) {
case Protocol.Chat: //Handle Chat
break;
case Protocol.Login: //Handle Login
break;
case Protocol.Disconnect: //Handle Disconnect
break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.