how do i connect to the server socket using the ip address and port number( client is running on a different machine than server)

后端 未结 2 603
暖寄归人
暖寄归人 2020-12-17 05:58

Client program

public class client implements Runnable {

protected static String server_IP = \"141.117.57.42\";
private static final int server_Port = 5555         


        
相关标签:
2条回答
  • 2020-12-17 06:40

    To connect in your code you use:

    Socket socket = new Socket(server_IP,server_Port);
    

    So you could use:

    Socket socket = new Socket("192.168.1.4", 5555);
    

    It looks like you have this in your code so I'm not sure what problem you're having.

    Don't forget that you have to setup your router to forward ports if it is located outside of your local network.

    http://www.wikihow.com/Set-Up-Port-Forwarding-on-a-Router

    Don't forget that if you are running a firewall, this can also interfere with the connection.

    0 讨论(0)
  • 2020-12-17 06:48

    Update /etc/hosts
    Add following line

    127.0.1.1 192.168.10.109

    0 讨论(0)
提交回复
热议问题