Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

Advancing with Sockets

Hey guys!
I have made a topic here in the past regarding server and how to connect to one using java programs i'm coding.

So i have made the following codes:
Server: (Click to View)

Client: (Click to View)

I have a few questions i would love to get some help and guidance with!
  1. Which web host i can upload the "Server" jar\class to make it run online?

  2. Is there any importance to which port to choose? if so,  how to choose a port? because i just used a random port used in an explanation i found.

  3. How to make sure the server wont stop searching for requests?
    because now if i run Server and then Client on the IDE both send a message&answer then closes. even if i remove the socket.close(); command on the Server.
    should i recursivly call the Server constructor at the end of it? so it will initialize a new socket and wait for a new connetion?
    is it a dumb idea or there's better ways of doing it?

  4. How can i get the IP of the client's socket? i tried to print it out for debugging purposes but didn't find a function to do access it and do so.



Thanks for the help! it is very appreciated <3
Good deeds make a long distance.
1. Just get a cheap ass VPS
2. Use any open on the server and preferably not one reserved by another service
3. Accept them in a loop. Also for better approach - use something like Netty for nice server pipeline and easy non-blocking i/o. Also refrain from using object serialization, make a custom binary protocol or just use Jackson+JSON encoding or whatever else, object serialization theoretically might lead to RCE.
4. Socket#getInetAddress() / Socket#getRemoteSocketAddress()
(Jun 26, 2020 05:41 PM)yumidev Wrote:  1. Just get a cheap ass VPS
2. Use any open on the server and preferably not one reserved by another service
3. Accept them in a loop. Also for better approach - use something like Netty for nice server pipeline and easy non-blocking i/o. Also refrain from using object serialization, make a custom binary protocol or just use Jackson+JSON encoding or whatever else, object serialization theoretically might lead to RCE.
4. Socket#getInetAddress() / Socket#getRemoteSocketAddress()

Thanks for answering pal ! i saw your post and went straight to work on it. didn't notice i didnt actually reply so im updating here.


1. tried looking on a few, couldn't manage to make the .java file of the server run on any of them though. unfortunately :\
2. Thanks ! :)
3. So just throw the entire Server constructor code inside a while loop without a real ending loop? so it will continually open another server when sent back a response?
wont it cause any overload? or is it just the proper way to go?
Unfortunately im not aware of using Jackson nor JSON or any encoding at the moment.. nor serialization ;P i still have a lot more to learn..
4. Thanks ! it seems to be working (As i get the local IP obviously) . once ill manage to put the Server code on a VPS or something ill try again to see if i get different dynamic IP's.

If there's anyone more familiar with how to upload the JAVA class onto a server i would be REALLY happy!
Good deeds make a long distance.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by DoomslayerMar 16, 2021 08:19 AM 9 339 Mar 16, 2021 08:19 AM
Last Post: synchronizing
[C#] by indetectableSep 20, 2020 05:12 AM 13 440 Sep 20, 2020 05:12 AM
Last Post: riu41776
[Python] by xPrimodyJul 27, 2020 01:55 PM 3 163 Jul 27, 2020 01:55 PM
Last Post: Pernat1y