Socket Receive Buffer Size

Is there a way to determine the size of the TCPIP socket receive buffer in C #. I send a message to the server and expect a response when I'm not sure about the size of the receive buffer.

            IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("192.125.125.226"),20060);
            Socket server = new Socket(AddressFamily.InterNetwork,
                              SocketType.Stream, ProtocolType.Tcp);
            server.Connect(ipep);

            String OutStr= "49|50|48|48|224|48|129|1|0|0|128|0|0|0|0|0|4|0|0|32|49|50";

            byte[] temp = OutStr.Split('|').Select(s => byte.Parse(s)).ToArray(); 

            int byteCount = server.Send(temp);

            byte[] bytes = new byte[255];
            int res=0;
            res = server.Receive(bytes);
            return Encoding.UTF8.GetString(bytes);
+3
source share
2 answers

The size of the buffer used to receive data depends on the application or protocol. There is no way in the language to indicate how large your receive buffer should be. There is also no socket function that can be used that says, "you need 23867 bytes to receive this message." In general, your application should work out from the protocol what size should be the receive buffer and how to process it. Typically, the protocol will either:

  • indicate the number of bytes in the message.
  • (, hdlc, 0x7e, )

, . , , 2000 , 1000 , , , .

+6

TCP - . .

, . , , .

TCP : http://www.serverframework.com/asynchronousevents/2010/10/message-framing-a-length-prefixed-packet-echo-server.html, ++-, .

, , , . , .

x , , , x , , , .

, , , . , , ( ?) .

+4

Source: https://habr.com/ru/post/1783550/


All Articles