Results 1 to 3 of 3
- 12-23-2011, 04:31 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 4
- Rep Power
- 0
Accessing a Java server from the Internet
So I want to Create a simple java client and server that echo to each other through an internet network (not in LAN).
Just as a test, I setup my pc with a static ip and I have my router forwarding to that ip (start port 8800, end port 8800). Everything works when I test it locally. However not when I connect from a computer on an external network. I know that my client app is working fine because It doesn't throw any errors and it does connect to the specified global ip address I gave it. The problem lies in my server app. The thread goes to sleep when I call server.accept() and never accepts any incoming connections.
Also I know I did port forwarding correctly because I checked Open Port Check Tool after reading the someone having the same problem on stack overflow
Moreover, I installed an apache web server at port 80; just as a test, I tried to http my ip on a web browser(chrome) on port 80 and it prompted me for my username and password. Could it be that my router denies access to the client because I need to authenticate first? if so how? Otherwise, what is my problem?
here is the server code:
Java Code:package Server; import java.net.*; import java.io.*; public class Server { private static final int PORT = 8800; private ServerSocket servSock; private Socket clientSock; private static Server server; //singleton server /* Static getter method to get reference to singleton server */ public static Server ServerAccess() { try{ if(server == null) server = new Server(PORT); }catch(IOException e) { System.out.println("IOException has occured constructing server"); } return server; } /* Define a port on construction */ private Server(int port) throws IOException { servSock = new ServerSocket(port); } /* main accept thread */ public void AcceptIncoming() { try{ clientSock = servSock.accept(); //wait for the client OutputStream clientOut = clientSock.getOutputStream(); //get client's output DataOutputStream toClient = new DataOutputStream (clientOut); //send msg toClient.writeUTF("hello"); System.out.println("wrote to client"); //close all connections toClient.close(); clientOut.close(); clientSock.close(); }catch(IOException e) { System.out.println("IOException occured while accepting client"); } } public void CloseConnection() { try{ servSock.close(); } catch(IOException e) { System.out.println("There was an IOException closing socket"); } } public static void main(String args[]) { //accept an incomoing call once Server.ServerAccess().AcceptIncoming(); Server.ServerAccess().CloseConnection(); } }
- 12-26-2011, 10:20 AM #2
Re: Accessing a Java server from the Internet
You need to open the port on your computer too. If you are using Windows, add an Inbound Connection rule to the Windows Firewall.
- 01-06-2012, 07:31 AM #3
Member
- Join Date
- Feb 2010
- Posts
- 80
- Rep Power
- 0
Re: Accessing a Java server from the Internet
what username/password is the server asking, is it the domain credentials? and did you try printing out statuses like once the connection is established, you print 'connection established' on the console, and so on. although the program is not throwing exceptions, you might see the state of the connection.
you could also make a console printing on the server side.[why are you annoyed with my sig?]
Similar Threads
-
How to fetch java function from the internet
By sumosumo84 in forum NetworkingReplies: 1Last Post: 02-12-2011, 12:50 AM -
Accessing local file from server side using Java Application
By ersachinjain in forum JDBCReplies: 9Last Post: 09-01-2009, 07:17 PM -
Using java to access internet account
By elgem in forum Advanced JavaReplies: 3Last Post: 01-18-2009, 06:49 PM -
How to extract .dat file from the internet using Java?
By burian in forum New To JavaReplies: 3Last Post: 12-09-2008, 08:17 AM -
Help - problem with java when using internet
By badabing in forum New To JavaReplies: 1Last Post: 08-07-2007, 01:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks