Read variables of a message that is sent by a server using socket

前端 未结 1 862
一向
一向 2021-01-28 00:37

I am working on Passenger information system PIS(Train).So trains send their location to my server PIS using socket on port 8080

相关标签:
1条回答
  • 2021-01-28 01:28

    Looks like you don't need to detect anything and definitely should not be slapping this in a string to try and parse.

    You already know you are getting a bunch of integers back. You even know what order they are in. Use a BinaryReader to get you your numbers and proceed from there. Once you load your reader up, it should be as simple as calling BinaryReader.ReadInt32() to read the message's numbers one after another.

    I must also highly recommend you to look into using statements for your streams.

    using (var reader = new BinaryReader(networkStream))
    {
        var messageSource = reader.ReadInt32();
        var messageDestination = reader.ReadInt32();
    
        ... and so on ...
    }
    
    0 讨论(0)
提交回复
热议问题