What name do i use to connect to a server socket in java -
i writing telnet program in java using server socket , socket classes. current code client program. user types in server name , port connect on.
static socket getsocket() { while(true) { system.out.println("what server want connect on port?"); string info = sc.nextline(); string host = info.split(" ")[0]; int port = integer.parseint(info.split(" ")[1]); try { inetaddress ip = inetaddress.getbyname(host); return new socket(ip, port); } catch (unknownhostexception e) { system.err.println("the host unknown."); } catch (ioexception e) { system.err.println("network error."); } } }
i tried connecting on localhost, , worked. tried connecting friend on remote computer using ip address network name , did not work giving exception. name use connect remote server.
you need give friend your remote ip address.
Comments
Post a Comment