ฉันสงสัยว่าใน Async Sockets ของฉันใน c # การได้รับ 0 ไบต์ในการเรียก EndRead หมายความว่าเซิร์ฟเวอร์ตัดการเชื่อมต่อของเราจริง ๆ หรือไม่
ตัวอย่างมากมายที่ฉันเห็นแนะนำว่าเป็นกรณีนี้ แต่ฉันได้รับการตัดการเชื่อมต่อบ่อยกว่าที่ฉันคาดไว้มาก
รหัสนี้ถูกต้องหรือไม่? หรือ endResult ‹= 0 ไม่ได้มีความหมายอะไรเกี่ยวกับสถานะการเชื่อมต่อจริงๆ หรือ
private void socket_EndRead(IAsyncResult asyncResult)
{
//Get the socket from the result state
Socket socket = asyncResult.AsyncState as Socket;
//End the read
int endResult = Socket.EndRead(asyncResult);
if (endResult > 0)
{
//Do something with the data here
}
else
{
//Server closed connection?
}
}