简体   繁体   English

套接字服务器断开连接并重新连接缓冲区错误?

[英]Socket Server Disconnect and Reconnect Buffer Error?

I'm using the following TCP Sockets Server/Client example: http://www.codeguru.com/Csharp/Csharp/cs_network/sockets/article.php/c8781/我正在使用以下 TCP 套接字服务器/客户端示例: http : //www.codeguru.com/Csharp/Csharp/cs_network/sockets/article.php/c8781/

I'm also using the following CryptoStream example: http://www.obviex.com/samples/Encryption.aspx我也在使用以下 CryptoStream 示例: http ://www.obviex.com/samples/Encryption.aspx

Problem: Both Server and Clients communicate perfectly until I Stop the Server socket, wait a minute or so, then start the Server socket.问题:服务器和客户端通信完美,直到我停止服务器套接字,等待一分钟左右,然后启动服务器套接字。 Sometimes but not always I recieve a base64 error in the Encryption.aspx on line 'Convert.FromBase64String(cipherText);'...有时但并非总是我在“Convert.FromBase64String(cipherText);”行的 Encryption.aspx 中收到 base64 错误...

I know there is incorrect / corrupted data in the buffer probably left-over from stopping the socket.我知道缓冲区中有不正确/损坏的数据,可能是停止套接字后遗留下来的。 Then the new data comes in and the error occurs.然后新数据进来,错误就发生了。

Q. Will clearing the 'class SocketPacket; Q. 将清除 'class SocketPacket; solve this issue?解决这个问题?

Q. How do I clear the 'class SocketPacketsocketBuffer'?问:如何清除“类 SocketPacketsocketBuffer”?

Other suggestions are greatly appreciated..其他建议非常感谢..

One of the things you may find is happening is that one of the sockets is not being closed down properly.您可能会发现正在发生的一件事是其中一个套接字没有正确关闭。 The thing with sockets is that you need to make sure they get correctly closed or you set the server socket to reuse the address.套接字的问题是您需要确保它们正确关闭,或者您将服务器套接字设置为重用地址。

Try tcpview from sysinternals to view the status of sockets.尝试从 sysinternals 使用 tcpview 查看套接字的状态。 You can also use netstat to view the status of the sockets.您还可以使用 netstat 查看套接字的状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM