Click here to Skip to main content
15,888,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am coding a TCP/IP socket program with MFC VC++ that communicate with a server using keep alive socket options.
My client PC program have some processes as follows:

1. Making a client socket
- Use WSAStartup
- create client socket with ip address/ port number

ClientSocket = socket(AF_INET, SOCK_STREAM, 0);

2. trying to connect:
connect(ClientSocket, (struct sockaddr *)&ToServer, sizeof(ToServer));

3. Next setting necessary options
iMode = 1;// to set non-blocking mode
int iresult= ioctlsocket(ClientSocket, FIONBIO, &iMode);

4. Add another option
if (setsockopt(ClientSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&bEnable, sizeof(bEnable)) == SOCKET_ERROR)
...

5. This socket makes no error if I do not clise or terminate it.

After the problems are found if I change the client socket - close or re-open it.
1) If I want to close clientsocket, I cannot find the result success after use closesocket().
2) And I cannot open any other client sockets with same ip address and port number with option RE_Use
3) In the monitoring log of Winshark,
The server push keep alive messages to client(= this program is my pc) repeatedly every 30 seconds,and my client program reply to server.
4) Even though terminat my client program and after I run the same program, the server send same keep alive messages to me. My client program make no other sockets except existing socket.

It looks like as if server force to me to use not make additional socket but use only same used socket.

Question:
Which peer has mistake to use socket options? And what is it?

Only one thing I want to do is even server send and other messages, I want to close existing client socket, and make a new client socket.

Thank you.

What I have tried:

More 1 week wasted by this problem.
Posted
Updated 18-May-16 0:32am

1 solution

See the explanation of how to use these options at Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE (Windows)[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900