SFML community forums

Help => Network => Topic started by: lorence30 on October 26, 2015, 07:59:52 pm

Title: multiple tcp sockets connecting to a single port
Post by: lorence30 on October 26, 2015, 07:59:52 pm
is it possible to a multiple sockets to connect to a single port simultaneously?
Title: Re: multiple tcp sockets connecting to a single port
Post by: eXpl0it3r on October 26, 2015, 08:56:46 pm
If I it's what I think you're trying to ask, then the answer is no.
Title: Re: multiple tcp sockets connecting to a single port
Post by: lorence30 on October 27, 2015, 03:04:48 pm
sorry for the late reply, this is what i mean

sf::TcpListener listen;
listen.listen(5000);

sf::TcpSocket client1;
sf::TcpSocket client2;

client1.connect("192.168.1.101",5000); // successfully connected
client2.connect("192.168.1.101",5000); // failed to connect


but when i accept first the client1 from the server the client2 doesnt get any problem

client1.connect("192.168.1.101",5000); // successfully connected
listen.accept(client1);
client2.connect("192.168.1.101",5000); // successfully connected
listen.accept(client2);
Title: Re: multiple tcp sockets connecting to a single port
Post by: Jesper Juhl on October 27, 2015, 08:14:43 pm
Yes. Multiple clients can connect to the same listening socket. If this was not the case how would you have webservers dealing with thousands of browsers connecting to them on port 80 at the same time?
You just need to accept all connections and handle them; either on the same thread/process, multiple threads, multiple processes or whatever. It's perfectly doable.
Title: Re: multiple tcp sockets connecting to a single port
Post by: lorence30 on October 28, 2015, 10:34:54 am
If this was not the case how would you have webservers dealing with thousands of browsers connecting to them on port 80 at the same time?
this makes sense, i didnt think of this thanks guys :)