Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
# In the case of my communication program with PC and server using TCP/IP, I don't know the cause of re-connection error as follows.


1. One TCP/IP Server type A has a program which use 2 ports 502, 3999 -
502 port used for receiving data from PC, 3999 port used for sending data to same PC

2. In PC program, it is using VC++ using winsocks library, countpart program of the server is onto the Linux.

3. Of the Linux server, 3999 PORT is setting by keep alive TCP/IP options.

4. The problem is that when the server close socket using 502 anytime, and I verified the Fin/Fin Ack signals between two servers - PC and Linux server by checking in the wireshark.

5. Another program of PC cannot connect the 502 port - which is already closed - with same ip address to the server .

5. Even whatever I can do anything, I cannot re-connect to the server by same ip address and 502 port.

6. The WSAGetLastErrorcode = WSAEISCONN (10056)

7. The sample is that as follows.

int result= inet_pton(AF_INET, "192.168.0.222", /*server address */ ,ToServer.sin_addr);
ToServer.sin_port = htons(502);

int ret_code = connect(ClientSocket, (struct sockaddr *)&ToServer, sizeof(ToServer));

if (ret_code != 0)
{
Sleep(10);
retcnt++;
ret_code = WSAGetLastError();
if (ret_code == WSAEISCONN)
{
AfxMessageBox(_T("Connection Failed. Already binding with another process."));
goto EXIT;
...

8. Finally, the question is :
One server using two ports close only one TCP port, another foreign application cannot connect the closed same port

Where is the missing points?

Thank you advancely,

What I have tried:

I wasted 2 months long time to solve this problem.
Posted
Updated 2-Nov-16 2:26am

1 solution

It looks like the problem is located at the server side.

A server typically:

  • Creates a socket
  • Binds the socket to a local address
  • Listens for connections
  • Accepts connections using a new socket
  • Serves requests using the connection related socket
  • Closes the connection and the related socket
  • Will be back in listening state


From your description it seems that you close the initial server socket and not the connection related one (or both), or do not return to the listening state.
 
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