VB .net获取服务器端套接字的客户端连接参数
我希望客户端和服务器都能分别写入和读取。以恒定速率(可以在客户端的 GUI 上配置)到缓冲区。
比如说,
- 我能够以每个数据包 150 字节的速度从客户端发送
- 现在,我也应该能够在服务器上以每个数据包 150 字节的速度读取数据。
既然两者都是通过套接字连接的,我们可以检索套接字参数(设置使用 tcpServer 对象从服务器端获取客户端大小(例如此处的 150)。
或者是否必须发送一个初始设置数据包来告知这些客户端参数,以便服务器可以继续?
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,
- I am able to send from the client at 150 bytes per packet
- Now, I should be able to read also at 150 bytes per packet on the server too
Since, 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在应用程序级别对消息大小进行排序是很常见的。您确实可以在成功连接后发送“设置消息”作为第一个数据。您应该以不会因字节顺序或每次读取调用接收到的字节数而被误解的形式发送此设置消息。也许是 ASCII 格式的固定大小消息,也许是 5 个字节:
“00150”
然后,服务器只能读取 5 个字节,转换为整数,将其保存在服务器-客户端套接字对象中,以便服务器始终知道要发送多少字节,以及然后发出该字节数的读取调用。
或者,您可以使用一个简单的协议将大小嵌入到每条消息中,例如:
SOH
“0”
“0”
“1”
“5”
“0”
[150字节数据]
EOT
Rgds,
马丁
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