小编Amr*_*ada的帖子

如何使用 IP 地址和端口号连接到服务器套接字?(客户端运行在与服务器不同的机器上)

客户端程序

public class client implements Runnable {

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


public static void main(String[] args) throws IOException{
    final  String host = "localhost";
    int init = 0  ;
    
    try {
        InetAddress iAddress = InetAddress.getLocalHost();
        client_IP = iAddress.getHostAddress();
        System.out.println("Current IP address : " +client_IP);
    } catch (UnknownHostException e) {
    }
    
    try {System.out.println("hello1");
        Socket socket = new Socket(server_IP,server_Port);
        System.out.println("hello3");
        init = initialize(socket);
       
    }catch (SocketException e) {
        System.out.println("Error: …
Run Code Online (Sandbox Code Playgroud)

java sockets serversocket

3
推荐指数
1
解决办法
6万
查看次数

标签 统计

java ×1

serversocket ×1

sockets ×1