Re: listening to several ports at a time
feboll@gmx.de wrote:
Andrew Thompson schrieb:
feboll@gmx.de wrote:
..
How can i write my code in order to listen on several ports at a time?
This multi-threaded server/client example should get you started..
<http://java.sun.com/docs/books/tutorial/networking/sockets/clientServer.html>
....
THX for the link - but the spawned thread is using the same port and
the same socket though!
I am guessing threads would be the way to go about listening
to a number of sockets. That example should be easily adaptable
to using multiple sockets*.
I would like to listen to several ports at a time, and switch programm
action on the requested port number.
Do I need to manually run a thread for each port to listen on?
I am not sure what you mean by 'manually', but you
either need to write code for each one, or common
code (e.g. a method) to be called each time a new
socket is required.
* I ran the Server/Client example once, and developed
something similar for a school project, but my
experience with sockets and client/servers is not
very extensive.
Andrew T.