multithreading - Java TCP server socket accepting multiple clients on different ports -


i trying build socket capable of having multiple tcp connections, @ different ports multiple clients simultaneously.

the situation socket has receive commands server , redirect commands wireless sensors (one command 1 sensor, not broadcasting), , able collect corresponding data sensors , send them server. connections server using tcp, connections sensors tcp or udp. main concern tcp connections. looking java multithreaded or thread pooled socket tutorials. examples i’ve seen using single port handle connections. i’m trying other possible solutions: utilizing tomcat server, java servlet/jsp, socket channel etc…

i’m not expert in networking or socket programming hope experience point me in right direction. thank can provide in situation.

not sure if understand seems unnecessary me obtain multiple ports situation. seems need focus on multi threaded sockets , java nio topics?

and again thank advice , help.

this rather big project answered in full here. here general guides:

1) if want create socket on 1 port need create 1 thread run it. called server socket. therefore, main thread u need call 1 thread every socket on every port.

2) each server socket keeps listening on port , waits clients connect. when client connects, server socket should open thread connection alone , return listening.

while(myserversocket.accept()) { open connection thread }

my advice learn online how open threads classes , follow guide above.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -