So in this post we shall see how to write a socket server on windows using the winsock api. Winsock is the socket api on windows and can be used to write socket speaking applications. The code shall be in C. So a socket server is an application that runs on a machine and expects clients to connect to it so that it can serve them. Hi, Thank you for the great job! I began 1 week ago to learn the programming with C++. I am writing my MasterThesis and should make a Socket-programm on windows.
Active1 year, 6 months ago
I am developing a RTSP Source filter in C++, and I am using WINSOCK 2.0 - blocking socket.
When I create a blocking socket, I set its
SO_RCVTIMEO
to 3 secs like so:My filter tries to connect to
IP_ADDRESS:554
(554 is RTSP server port). If there is a server listening on that IP on the port 554, all goes well, but:- If my filter creates a socket to an existing IP address, but on a random port which no one listens on,
connect()
waits for 3 secs and returnsWSAETIMEDOUT
. So after 3 secs, I know that the provided URL is bad. - If my filter creates a socket to a non existing IP address, and tries to connect it, it hangs for about 10 secs before returning SOCKET_ERROR. So,
SO_RCVTIMEO
gets ignored if the IP doesn't exist on the network..Automation testing: Many sub challenges – Should automate the testing work? Till what level automation should be done? Do you have sufficient and skilled resources for automation? Is time permissible for automating the test cases? Decision of automation or manual testing will need to address the pros and cons of each process. Knowledge 2nd edition at a guide to the automation body of knowledge, pdf download a guide to the automation body of knowledge - pdf free download a. SWEBOK V3.0 is the most recent completely revised and updated version of the internationally respected Guide to the Software Engineering Body of Knowledge. Agile Tester Extension Material for. Download free test automation body of knowledge pdf free. Download Free Test Automation Body Of Knowledge Pdf File. 1/10/2018 0 Comments. Once you register and pay the fee, you would receive the ” Software Testing Body of Knowledge (STBOK) for CAST (367 pages) book. The enrollment is same as that for the foundation level. • to download the syllabus for Test Analyst • to download the. Download Free Test Automation Body Of Knowledge Pdf Converter. 5/6/2017 0 Comments. There are currently no industry- accepted accelerated test methods to judge a particular product’s propensity to form whiskers. Due to the difficulties in predicting tin whisker growth, it may not be possible to completely eliminate tin whiskers as a. The Complete API Test Automation Framework for SOAP, REST and More. Download SoapUI NG Pro. The Cadence Allegro ® FREE Physical Viewer is a free download that allows you to view and plot databases from Allegro PCB Editor.
QUESTION:How can I set the timeout for a non existing IP, in the second case? Do I need to send ICMP PING first to see does the IP exist, or perform some other check like that?
Any help will be appreciated. Thanx. :)
THE ANSWER TO MY PROBLEM
Because I am using blocking sockets, call to
connect()
blocks, until the connection is made, or the connection fails because the host is not responding, or it is refusing connection. If I set socket's timeout to be 3 seconds, and try to connect to a host that doesn't exist, my pc (client) will send TCP packet with SYN
flag set, to initiate the Threeway handshake. Normally, the host, if up, will respond with TCP packet containing ACK
and SYN
flags set, and then, client (me) would send the TCP packet with ACK
flag set. Then the connection is made. BUT if the host is down, and the SYN
is sent, client waits until the 3 second timeout expires, and then tries AGAIN, and AGAIN, until the TcpMaxConnectRetransmissions
(MICROSOFT ARTICLE) registry setting is reached, because the host can be UP but the SYN
packet might get lost.. My Windows XP has this setting at 4, I guess, so each time it tries to send SYN
, it waits 3 seconds, and when the fourth try fails, it returns SOCKET_ERROR
(after 12 secs), and sets WSAETIMEDOUT
as the last WSA error.The way around this is using non blocking sockets, and trying to manually measure the connection attempt time (because now the
connect()
wouldn't block) as Martin James suggested.Another way is to fiddle with the registry, which is the last resort..
Cipi
CipiCipi9,05888 gold badges4040 silver badges5656 bronze badges
3 Answers
Bite the bullet. The remote IP may not be running a PING server or PING may be blocked by some router, so it's no help. Can you not just wait the 10 sec and then make whatever error indication you use?
If you absolutely have to time out the attempted connection after 3 seconds, you can time it out yourself.
Martin JamesMartin James22.4k33 gold badges2929 silver badges5454 bronze badges
Actually, Berkeley sockets have not timeout for connect, so you can not set it.ICMP PING is not helpful, i don't know why, but if host not exists you spend around 1 second with PING. Try use ARP for detect is host exists.
xandoxxandox
from cmd you can ping the ip with a timeout like this 'ping -w 100 -n 1 192.168.1.1'
it will return within 100mS
you can check the return code by 'echo %errorlevel% 0 = ok, 1 = fail, then you know if you should try connect
in c++
stevehsteveh78422 gold badges1818 silver badges3535 bronze badges