Answer the question
In order to leave comments, you need to log in
How to establish a connection to the ServerSocket of the local computer from a mobile device?
Good day to all.
As part of my pet project, I needed to make a quick data exchange between the server and mobile devices. I have this client code:
public class TestRunnableClientTester implements Runnable {
static Socket socket;
@Override
public void run() {
try {
socket = new Socket("192.168.100.26", 4444);
} catch (Exception e) {
e.printStackTrace();
}
try (
DataOutputStream oos = new DataOutputStream(socket.getOutputStream());
DataInputStream ois = new DataInputStream(socket.getInputStream())) {
int i = 0;
while (i < 1000) {
oos.writeInt(i);
oos.flush();
int in = ois.readInt();
System.out.println(in);
i++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
socket = new Socket("192.168.100.26", 4444);
Answer the question
In order to leave comments, you need to log in
Hello.
Where is this code being executed? Where is the server? If on another device, then the problem may lie in port forwarding on the router. Then, you need to specify the ip of the computer where the server is raised and the port that the server is listening on.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question