I’m trying to open a socket to a website over the Internet, but can’t. After about a minute, a ConnectException is thrown saying that the operation timed out.
Socket clientSocket = new Socket(InetAddress.getByName("gmail.com"), 25);
My computer is connected to a router, which is connected to the Internet. My router is configured to direct all incoming port 25 data to port 2550 on my local machine (192.168.2.2). So, I thought maybe if I set the “local address” and “local port” parameters on the Socket constructor it might work…but this also gives me an “operation timed out” error.
Socket clientSocket = new Socket(InetAddress.getByName("gmail.com"), 25, InetAddress.getByName("192.168.2.2"), 2550);
I saw this SO question, but was wondering if anyone could shed any more light on the issue. Thanks.
You are trying to connect to port 25 on
gmail.com, but that machine is not an email server. You must first look up the MX record forgmail.com, and then try to connect to one of the delivery servers mentioned in the returned MX record.For example, with
dig mx gmail.comon my machine, I get:So try connecting to port 25 on
gmail-smtp-in.l.google.com(which is the server with the lowest MX priority number).