gpt4 book ai didi

c# - C#中的套接字问题

转载 作者:行者123 更新时间:2023-12-03 11:50:55 25 4
gpt4 key购买 nike

Socket socket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
...
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 1000);
...
socket.Send(bytesSent, bytesSent.Length, 0);
...
bytes = socket.Receive(bytesReceived, bytesReceived.Length, 0);

套接字发送数据后,服务器不响应,因此程序等待响应。如何在1000毫秒后停止接收数据? Ы

最佳答案

在调用socket.Receive(...)之前,请设置此属性。从MSDN

socket.ReceiveTimeout = 1000;

关于c# - C#中的套接字问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/698692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com