简体   繁体   English

检查服务器收到的第一条消息的最佳方法是什么?

[英]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.

相关问题 检查 S3 object 是否存在的最佳方法是什么? - what's best way to check if a S3 object exists? 在ASP.NET中检查用户浏览器的最佳方法是什么? - What is the best way to check the user's browser in ASP.NET? 在文本框中检查所需信息的最佳方法是什么? - what's the best way to check for required information in a textbox? 以编程方式测试 SQL 服务器连接的最佳方法是什么? - What's the best way to test SQL Server connection programmatically? 在Web服务器上部署可执行进程的最佳方法是什么? - What's the best way to deploy an executable process on a web server? 什么是多线程的最佳方式? - What's the best way to multithread? 发送消息的最佳做法是什么 - What's the best practice to send a message 将应用程序时间与外部服务器时间同步的最佳方法是什么? - What would be the best way to synchronize my application's time with outside server's time? 从控制器操作向Ajax请求对象返回“未经身份验证”消息的最佳方法是什么? - What's the best way to return an “Unauthenticated” message from a controller action to an Ajax request object? 拆分字符串列表以匹配首字母和最后字母的最佳方法是什么? - What's the best way to split a list of strings to match first and last letters?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM