sockets - Getting connection errors while making a server/client chat program in java -
i'm near done project yet i'm trying make sure things working , more client , server connecting, , i'm getting connection errors. here 2 programs. i'm not entirely sure how run both of them @ once in eclipse maybe problem. appreciated
import java.net.*; import java.util.*; import java.io.*; public class server { public void main(string[] args)throws exception { serversocket server = new serversocket(3333);; while (true) { socket clientsocket = server.accept(); scanner sc = new scanner(clientsocket.getinputstream()); printstream p = new printstream(clientsocket.getoutputstream()); string message = "hello server"; p.print(message); } } and heres client
public static void main(string[] args)throws exception { client display = new client(); display.setvisible(true); try { socket server = new socket("localhost", 3333); scanner sc = new scanner(server.getinputstream()); printstream p = new printstream(server.getoutputstream()); system.out.println(sc.next()); server.close(); sc.close(); p.close(); } catch (unknownhostexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } i have gui stuff above , below client didnt show. when run these following errors
java.net.connectexception: connection refused: 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) @ client.main(client.java:56) and line 56 line -- socket server = new socket("localhost", 3333);
Comments
Post a Comment