Reputation: 5952
Using Java sockets, I made a simple server. This works because it sends data whenever I enter in the address (192.168.1.68:54321
) into another computer's web browser. But when I attempt to connect to the server using a Java socket, it times out.
Client connect code:
public void connect() throws IOException {
socket = new Socket(ip, port); // times out here
socket.setKeepAlive(true);
in = new ObjectInputStream(socket.getInputStream());
out = new ObjectOutputStream(socket.getOutputStream());
t = new Thread(this);
run = true;
t.start();
}
What is a solution to this problem?
Upvotes: 0
Views: 197
Reputation: 718718
What is a solution to this problem?
It depends on what the problem is. But I expect it is one (or more) of the following:
Of these, I think that the last is the most likely.
(Note that many of these issues are more likely to result in a different failure mode; i.e. an immediate failure rather than a connection timeout. However, that depends on a variety of details about your environment, some of which are likely to be opaque to you.)
The rest shouldn't be problems since it works on the same computer as my client when I use a web browser.
You are mistaken. Your web browser will NOT be successfully connecting to your service. The service on 54321 doesn't implement HTTP, so your browser can't fetch pages from it.
Firewall rules for TCP and UDP tend to be specific to the ports that you are trying to use. The fact that your web browser can talk to the server on (I expect) ports 80 and 443 says NOTHING about whether something else can connect on some other port. And there is the further complication that your web browser could be configured (or auto-configured) to use a web proxy, and that could mean that it is not talking to that host directly at all.
Given what you've said, it is highly likely to be a firewall related problem. That is my best answer.
Upvotes: 1