I'm trying to connect two MacBooks using Java network programming, one is a server and the other is a client. In server, I wrote something like
ServerSocket s = new ServerSocket(8008);
and then in my client computer I wrote
hostname = "Alex";
Socket socket = new Socket(hostname, 8008);
where "Alex" is the computer name of my server, found in System Preference -> Sharing -> Computer Name, as shown in the screenshot. However when I run the script on client I got the following error message:
error: Alex
java.net.UnknownHostException: Alex
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:564)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at java.base/java.net.Socket.connect(Socket.java:583)
at java.base/java.net.Socket.<init>(Socket.java:507)
at java.base/java.net.Socket.<init>(Socket.java:287)
at EchoClient.main(EchoClient.java:9)
It seems that the hostname of my server is not recognized. Then where should I look up the hostname of my server computer?
Thanks!