Server-Client-Server

20 Jun 2011

Hi! I'm programming an application which change , first, from server to client, and then comes back to server. I'm using the TCPSocket library, and in the last change (commming back from client to server) I´ve got a bind error. The sequence is the next: 1) SERVER: I bind the socket with "IP" and "port" and listen waiting for the connection. I accept the communication, and I create a new socket for the interchange of information, handling the events on this socket.

Now I want to be a client.

2)CLIENT: I close the two sockets I was unsing on the SERVER mode, and I open a new one, and connect it with "IP2" and "port2".

Now I want to be a server again.

3)SERVER: I close the socket I was using on the CLIENT MODE, and I do the same that in step 1). I want to use the same IP and port, but I´m not sure if I can.

My doubt is if after closing a server socket, is possible to open it again with the same IP and port.

Can anybody help me? Thanks!!

21 Jun 2011

I´ll simplify the question:

I have a server with a "socket" ( bind to an IP and port) to listen the connectios and a "pCLientSock" to send and receive data. I want to close them and restart again the server with the same IP and port. If I close socket, and pClientSock, is enough ? Because if I do that, and I bind again the "socket" to the same IP and port , I have a "bind error" and I don´t know how to remove or reset the sockets... thanks!