For some reason, only the first message from the client gets displayed. Here's the code.
Code:public static void serverStart(int port) throws IOException { ServerSocket s = new ServerSocket(port); System.out.println("Server is now awaiting for incoming connections on port " + port); Socket client = s.accept(); System.out.println("Client from " + client.getInetAddress() + " connected!"); while (true) { try { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(client.getOutputStream())); DataInputStream in = new DataInputStream(new BufferedInputStream(client.getInputStream())); String message = in.readUTF(); System.out.println("Client sent message: " + message); } catch (IOException e ) { } } }Check the terminal stuff out:Code:public static void clientConnect(String hostname, int port) throws IOException { while (true) { try { Socket s = new Socket(hostname, port); DataOutputStream out = new DataOutputStream(new BufferedOutputStream(s.getOutputStream())); DataInputStream in = new DataInputStream(new BufferedInputStream(s.getInputStream())); System.out.println("Enter a message to send to the server:"); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); String message = stdin.readLine(); out.writeUTF(message); out.flush(); } catch (IOException e) { } } }
http://img253.imageshack.us/my.php?image=problemqo7.jpg
When i tyed the first message on the client, the server got it. but when i typed the other stuff, server didnt output anything :s




Reply With Quote