http://www.vchelp.net/cndevforum/subject_view.asp?subject_id=115415
PROXYWIN direction Posted on 2004-10-22 18:12:42 [50 points]
Calling Sendto on the UDP socket to send the data to the receiving end, very strange, if the peer machine is not started, this SendTo is blocked for a long time, and then returns to send success. Once the peer starts, Sendto will return soon. Why do UDP send data, this happens, is it not connected? By there are many data reports to others, it will be blocked in this place. That is to say, each other can make me The server is rotten. Ask. Proxywin direction returned from 2004-10-22 18:54:22
This forum is over the 2nd floor of Proxywin Directions Reply to 2004-10-22 18:55:08
I played myself for the 10th floor of William_xiong Ten Layers. Reply to 2004-10-22 19:02:53
Do you use a SELECT model? If you use a thread, you won't have the case you say. Proxywin direction Reply to 2004-10-22 19:37:15
Thank you fossil. I finally had a message. I used the thread and the SELECT function, and select immediately succeeded, but I can't send it, because the peer didn't get up. After you get it, why is it like this, it It's okay. Is it still possible to stop? And use setsockopt (M_HSOCKET, SOL_SOCKET, SO_SNDTIMEO, (CHAR *) & TIMEOUT, SIGEOF (Timeout)); set Sendto's maximum blocking time can not succeed, although the function returns 0, but getSockOpt The maximum blocked time will always be 4 seconds. That is, if the opposite end does not start, each thread issued a datagram, it is to be blocked for 4 seconds, and the subsequent data report is all blocked. I can't always get a thread every customer. Please ask William_xiong Ten 5th floor to pay back in 2004-10-22 19:59:49
Yes, if your Winsock is Winsock2 previous version, you can call WSAcAncelBlockingCall () to cancel the shallow call call. Or through the IOCTLSocket () Setup mode, if Winsock 2.0, you can set the working mode of the socket by wsaiocTl (), that is, set to non-block SAI mode, Note: If you use wsaasynselect () or wsaeventselect () The function will be automatically set to non-block SAI mode. Proxywin direction Reply to 2004-10-22 20:38:35
Thanks for the fossil! Set to a non-blocking can solve the problem. But the roots have not been resolved, then ask the UDP's stories: When the server is not yet, the client calls Sendto on the UDP socket to send it to it. Many UDP datagrams. As a result, due to the peer is not reached, the client UDP socket state is abnormal: Schlect will be readable, but the recvfrom returns -1, the error code is 10054, that is, the connection is reset Moreover, the SENDTON is unpacular UDP packet, which makess N times have such a false readable, to call Recvfrom to skip these false readings. At that time, the udp knew that the other party is not arrival, insects The worm is telling the feedback ICMP packets leading to UDP sockets. My question is, how to skip this N times SELECT hypothesis? If you have sent a lot of non-accessible data report in front, if you use SELECT and Recvfrom is too low, and it will also cause the client to launch the real datagram that returned for a long time. Or how do ICMP from modifying my UDP socket status? Or, how to ban ICMP on the peer Response? I refer to the implementation. Thank you William_xiong Ten 2nd floor Reply to 2004-10-22 21:41:09 This response is accepted as the correct answer first, if this problem is handled at the bottom, it is not necessary, because This problem can be avoided in programming, give you a scheme for reference, the client generally has a login operation after startup, if the login is successful, the server will send the online user to the client, if there is no, at least It should also return the server to a successful ACK, if the ACK is successful, then send data, otherwise, it is regarded as the other party to not reach, no need to send data, the ProxyWin direction returns from 2004-10-23 8:00:47
This way, the customer login check can be made to the mechanism you said, but once the UDP datagram is started to send to customers, the server cannot identify this customer's disconnection: If this customer is broken for 1 second, it recovered Then, the server-side UDP socket causes the socket to be an abnormally readable state due to Sendto's unpachable datagram, and these readable status backlogs N (number of data sent within 1 second). Because I implemented a heartbeat detection mechanism, because this UDP socket is abnormal, I can no longer read the client feedback back Hello Ack, only think that customers are disconnected. This is unrecognizable. Use a loop to read the UDP socket until it is not read, which can skip these exceptions in a short time, but if you send a huge data report in the break in a few seconds, then this loop is huge , Equal to Sendto, this will seriously affect efficiency) What is the high of fossil? William_xiong Ten 9th floor Reply to 2004-10-23 23:33:01
Oh, in fact, the return value of Sendto (...) can be deemed to be sent successfully as the size size of the buf, otherwise, it is considered to be unreachable, then WSAGetLastError () is used to get the error message, you use this return Value first try it,