Varifying Socket Connection :: Winsock
Hi.
I was wonder about the best way to varify if a socket is currently active. In other words, I need a way to determine if there is a connect on a socket. This is just for command update UI. Basically, if the socket is active, I enable/disable something. If not, I enable/disble something.
How about this code?
// if (mysocket == WSAENOSOCKET)
// socket is invalid or inactive
Thanks,
Kuphryn
[437 byte] By [
kuphryn] at [2007-11-17 11:49:52]

# 1 Re: Varifying Socket Connection :: Winsock
What side of your app are you coding?
if it is a client, when you call Connect() you should get an OnConect() event (if using MFC)
The OnConnect has info about the result of the connection.
---------
_Leo_
http://www.drk.com.ar
_Leo_ at 2007-11-10 8:06:57 >

# 2 Re: Varifying Socket Connection :: Winsock
Thanks.
I am working on both side of the Winsock program including server and client. The user has the other top start a server or connect to on.
Kuphryn
# 3 Re: Varifying Socket Connection :: Winsock
You should work on the server side first... the go to client side when it is finished.
To test your server during its development process you can use TCP/IP Builder -> http://www.drk.com.ar/builder.php
---------
_Leo_
http://www.drk.com.ar
_Leo_ at 2007-11-10 8:08:57 >

# 4 Re: Varifying Socket Connection :: Winsock
Nice. Thanks
I'll try it out once I get everything going.
The design is complete. I am done with all the code. The program is in debugging phase. I am experience an error with getaddrinfo(...).
Kuphryn
# 5 Re: Varifying Socket Connection :: Winsock
What are you using getaddrinfo() for?
---------
_Leo_
http://www.drk.com.ar
_Leo_ at 2007-11-10 8:10:52 >

# 6 Re: Varifying Socket Connection :: Winsock
I use getaddrinfo to setup a sockaddr for a socket I want to use to connect to a server (running the same program).
Basically, here is the ocde for WSAConnect(...).
--
if (WSAConnect(s, socketaddr->ai_addr,
socketaddr->ai_addrlen, NULL, NULL, NULL, NULL) != 0)
DetermineErrorWSAConnect();
--
I am test the program via one way. In other words, I am trying to connect to a server that does not exist. Maybe that is what is causing the errors.
Kuphryn
# 7 Re: Varifying Socket Connection :: Winsock
why don't you fill up socketaddr structure by hand? (to be sure getaddrinfo(by the way I can't find this function in MSDN...))
you can use this function:
INT WSAStringToAddress(
LPTSTR AddressString,
INT AddressFamily,
LPWSAPROTOCOL_INFO lpProtocolInfo,
LPSOCKADDR lpAddress,
LPINT lpAddressLength
);
if you try to connect to a non-existing machine or the port you are trying to reach in this machine is not listening for connections, WSAConnect will fail for sure.
for tesintg purposes you may try with the IP of a known working mailserver(popserver) at port 110
---------
_Leo_
http://www.drk.com.ar
_Leo_ at 2007-11-10 8:12:56 >

# 8 Re: Varifying Socket Connection :: Winsock
Thanks.
I might try stringtoaddress function. However, right now, I have found the source of a problem. The program crashes when I try to connect to anything. The source of the problem is WSAConnect(...). The program crashes with an access violation error.
Maybe there is a pointer error somewhere. I have to recheck.
Kuphryn