Java networking server-client error -
i'm trying programme (simple, starters) server-client thingy, found connection , see if works. , does. long remain within own 4 walls/network. seek go via routers ip client produces mighty fine error message. usual suspects have been eliminated: router port forwarding on, firewall doesn't interfere (well, still doesn't work when turn off), , canyouseeme.org says can found connection chosen port when server runs.
here source code server, since figured out possible go via command line little telnetting. when seek found connection, says could not open connection host, on port 49163:connection failed
server:
import java.net.*; import java.io.*; public class chatserver { public static void main(string[] args) throws ioexception { serversocket server = null; seek { system.setproperty("java.net.preferipv4stack" , "true"); server = new serversocket(49163); } grab (ioexception e) { system.err.println("could not hear on port: 49163."); system.exit(1); } socket client = null; seek { client = server.accept(); } grab (ioexception e) { system.err.println("accept failed."); system.exit(1); } printwriter out = new printwriter(client.getoutputstream(), true); bufferedreader in = new bufferedreader(newinputstreamreader(client.getinputstream())); string inputline; string outputline; out.println("connection established"); while ((inputline = in.readline()) != null) { if (inputline.equals("exit")) { break; } outputline = inputline; out.println(outputline); } out.close(); in.close(); client.close(); server.close(); system.out.println("server offline"); } }
oh yeah, preferip4vstack picked on stackoverflow, doesn't seem work me.
for reason i'm not able inlcude code client, maintain getting messages formatting, , can't figure out. way see i'm not able connect via command line (when seek connect "real" ip), client doesn't have involved. want see error anyway:
java.net.connectexception: connection refused: connect @ java.net.plainsocketimpl.socketconnect(native method) @ java.net.plainsocketimpl.doconnect(unknown source) @ java.net.plainsocketimpl.connecttoaddress(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) @ chatclient.main(chatclient.java:12)
could not open connection host, on port 49163:connection failed
no didn't. thats not java message. code said that, when caught connectexception had much more detailed message of own. print , might have hope of finding went wrong. making own messages , suppressing exception tells if ever idea.
the message 1 of:
'connection refused', means got target host or port wrong, or there firewall 'connection timed out', network connectivity problem 'no route host', ip routing problem 'unknown host', 1 time again means got server name wrong. java networking connection
No comments:
Post a Comment