开发者

VB .net get the client connection params of the socket on server side

开发者 https://www.devze.com 2023-04-04 08:23 出处:网络
I want both the client and server to write and read resp. at a constant rate (which can be configured on the GUI of the client) to the buffer.

I want both the client and server to write and read resp. at a constant rate (which can be configured on the GUI of the client) to the buffer.

Say,

  1. I am able to send from the client at 150 bytes per packet
  2. Now, I should be able to read also at 150 bytes per packet on the server too

开发者_如何学CSince, both are connected through a socket, can we retrieve the socket params (set on the client size, like 150 here) from the server end, using the tcpServer object.

Or is it must to send an initial setup packet which tells about these client params and so accordingly the server can continue?


It's kinda usual to sort message sizes out at the application level. You could indeed send a 'setup message' as the first data after a successful connect. You should send this setup message in a form that will not be misunderstood due to endianness or the number of bytes received per read call. Perhaps a fixed-size messge in ASCII, maybe five bytes:

'00150'

The server can then read five bytes only, convert to integer, save it in the server-client socket object so that the server always knows how many bytes to send and then issue a read call for that number of bytes.

Alternatively, you could use a simple protocol that embeds the size into each message, eg:

SOH "0" "0" "1" "5" "0" [150 bytes of data] EOT

Rgds, Martin

0

精彩评论

暂无评论...
验证码 换一张
取 消