+ 2

[SOLVED] Cross-device Java socket connection

Hi, I had a question about Java sockets. I have only seen the client and the server both running on the same device. Is it possible for them to be on different devices and still do the communication? Like the server is in a separate device and the client is on another device with no wire-link in between. I am referring here java.net.ServerSocket and java.net.Socket.

1st Jun 2022, 12:49 PM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar
4 odpowiedzi
+ 2
Just from doing some googling, it looks like you can, you just need to make sure you're connecting to the same port. Like have both devices connect to port 5000. Try these answers from SO: https://stackoverflow.com/questions/10131377/socket-programming-multiple-client-to-one-server https://stackoverflow.com/questions/15694630/multiple-serversockets-multiple-devices-and-sending-to-multiple-sockets
1st Jun 2022, 1:21 PM
Justice
Justice - avatar
1st Jun 2022, 5:36 PM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar
+ 1
User42 I am glad it helped 👍
2nd Jun 2022, 1:49 PM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar
0
Justice thank you very much
1st Jun 2022, 1:41 PM
Bhaveshsingh Pawar
Bhaveshsingh Pawar - avatar