I am trying to create a server that listens on a list of ports in a user-specified range. It will accept the connection, receive the file from a sender, then close the socket. There is a new socket for each thread and each socket is tagged to a port (I think!).
This is where my issue lies. When I close the connection, the last thread activated tries to accept a connection and says the connection is not in a listening state. Then, when I try to create a new socket using the initial port says that another socket is already listening on the same port.
It seems that though I'm trying to tell each socket to use a specific port, they ignore that instruction.
My pseudo code would be:
Create a map of ports and their use status(bool - initially set to true for available).
while(){
Pick a port and set its status to unavailable.
Use getaddrinfo to give the addrinfo structure the port number.
Create a socket using the information from the addrinfo struct.
Create a thread within a Receiver class by passing the socket and filepath as parameters to the object constructor.
Add the thread ID and port number to a new map for monitoring purposes.
When the thread has finished, remove it and the port number from the map.
}
I'm not overly familiar with socket programming, so I may be missing some key points.
Thanks in advance.
EDIT: I realised to late that I put this in Open Discussion, not Help. Apologies.
Last edit: Christopher Paton 2013-02-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi everyone!
I am trying to create a server that listens on a list of ports in a user-specified range. It will accept the connection, receive the file from a sender, then close the socket. There is a new socket for each thread and each socket is tagged to a port (I think!).
This is where my issue lies. When I close the connection, the last thread activated tries to accept a connection and says the connection is not in a listening state. Then, when I try to create a new socket using the initial port says that another socket is already listening on the same port.
It seems that though I'm trying to tell each socket to use a specific port, they ignore that instruction.
My pseudo code would be:
Create a map of ports and their use status(bool - initially set to true for available).
while(){
Pick a port and set its status to unavailable.
Use getaddrinfo to give the addrinfo structure the port number.
Create a socket using the information from the addrinfo struct.
Create a thread within a Receiver class by passing the socket and filepath as parameters to the object constructor.
Add the thread ID and port number to a new map for monitoring purposes.
When the thread has finished, remove it and the port number from the map.
}
I'm not overly familiar with socket programming, so I may be missing some key points.
Thanks in advance.
EDIT: I realised to late that I put this in Open Discussion, not Help. Apologies.
Last edit: Christopher Paton 2013-02-19
It's OK. I solved the issue. It was due to my class initialisation. :)