Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: multiple tcp sockets connecting to a single port  (Read 2966 times)

0 Members and 1 Guest are viewing this topic.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
multiple tcp sockets connecting to a single port
« on: October 26, 2015, 07:59:52 pm »
is it possible to a multiple sockets to connect to a single port simultaneously?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: multiple tcp sockets connecting to a single port
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: multiple tcp sockets connecting to a single port
« Reply #2 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);
« Last Edit: October 27, 2015, 05:20:13 pm by lorence30 »

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: multiple tcp sockets connecting to a single port
« Reply #3 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.

lorence30

  • Full Member
  • ***
  • Posts: 124
    • View Profile
    • Email
Re: multiple tcp sockets connecting to a single port
« Reply #4 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 :)

 

anything