连接计算机最多的IP地址,Java:为了连接两台不同的计算机,服务器的IP地址是多少...

我已经在Java上设计了一个小型多人游戏,并已使用本地主机ip“ 127.0.0.1”成功地对其进行了测试,但是现在我想在都连接到Wifi网络的两台不同计算机上对其进行测试。

问题是我不知道客户端需要使用哪个IP地址来连接服务器。我已经使用了IPv4地址(在cmd ipconfig中),但是它们似乎没有连接。

客户:

public class Client {

Socket client;

ObjectOutputStream oos;

ObjectInputStream ois;

public Client(String gameServer) {

try {

client = new Socket(InetAddress.getByName(gameServer),8888);

oos = new ObjectOutputStream(client.getOutputStream());

ois = new ObjectInputStream(client.getInputStream());

} catch (IOException e) {

e.printStackTrace();

}

}

服务器:

public class Server {

ServerSocket ss = null;

Socket server;

ObjectOutputStream oos;

ObjectInputStream ois;

public Server() {

try {

ss = new ServerSocket(8888, 10, InetAddress.getByName("0.0.0.0"));

server = ss.accept();

System.out.println("----->" + server.getInetAddress().getHostName());

System.out.println("Successful connection");

oos = new ObjectOutputStream(server.getOutputStream());

ois = new ObjectInputStream(server.getInputStream());

} catch (IOException e) {

e.printStackTrace();

}

}

基本上,我不知道要输入什么作为Client类的构造函数来连接这两台计算机。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值