3

I have multiple threads using multiple sockets but all pointing to one port. Will it work? I have seen some threads saying multiple Applications cant use the same ports but I'm not sure it directly addresses this question

Example of the code

       static IPEndPoint b = new IPEndPoint(IPADRESS, PORT);
       static Thread listenThread = new Thread(listen);
       static Thread sendThread = new Thread(send);

       static void listen(){
          Socket socket = new Socket;
            socket.bind(b);
          while(exit == false){

          Socket.listen(10);
           //handle Data

                }

           static void send(){
          Socket socket = new Socket;
            socket.bind(b);
          while(exit == false){

          Socket.send(msg)
                }
silentcallz
  • 101
  • 4
  • 14
  • Here is a very nice answer that sums it up all: http://stackoverflow.com/a/724022/24472 – Larry Mar 31 '16 at 20:10

1 Answers1

1

If you have only one listening thread and one sending thread on the same port you are ok. But if more then make one thread listen to the port and push whatever received into queue. Other threads should read from the queue.

Riad Baghbanli
  • 3,105
  • 1
  • 12
  • 20