Java can not connect to Server Socket -


i have multi threaded server socket running on 1 computer running follows:

static void createserver() throws ioexception {     //use ip other user     system.out.println(inetaddress.getlocalhost());     // establish server socket     try {         serversocket s = new serversocket(8888);          while (true) {             socket incoming = s.accept();             runnable r = new threadedechohandler(incoming, map);             thread t = new thread(r);             t.start();         }     } catch (ioexception e) {         e.printstacktrace();     } } 

}

then computer try connect server(using ip first computer 192.168.162.1) follows:

public void registercmnd(scanner keys) throws ioexception {     inetaddress ip = inetaddress.getbyname("first computer ip");     try (socket s = new socket(ip, 8888)) {         .....         .....    }  } 

i getting java.net.connectexception.

exception in thread "main" java.net.connectexception: connection timed out: connect @ java.net.dualstackplainsocketimpl.connect0(native method) @ java.net.dualstackplainsocketimpl.socketconnect(unknown source) @ java.net.abstractplainsocketimpl.doconnect(unknown source) @ java.net.abstractplainsocketimpl.connecttoaddress(unknown source) @ java.net.abstractplainsocketimpl.connect(unknown source) @ java.net.plainsocketimpl.connect(unknown source) @ java.net.sockssocketimpl.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.connect(unknown source) @ java.net.socket.<init>(unknown source) @ java.net.socket.<init>(unknown source) @ user.registercmnd(user.java:45) @ user.main(user.java:28) 

any ideas?

it doesn't problem in code itself.

there number of possible causes this, including

  • a firewall, on client, server, hypervisor stack, or network blocking access.

  • you using wrong ip address server on client

  • you using wrong server port number on client (not in case)

  • you using ip address isn't routed client server. example, if server's ip private address, , client on different network.

  • someone has misconfigured packet forwarding (e.g. iptables) or routing (e.g. routed, etc) on client or server. or somewhere else.


if you, see whether 1 computer can ping other , vice-versa. if fails, check routing tables. note most likely network configuration problem, not programming problem.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -