Client blocks!



My client block after typing the first input...any ideas?


import java.io.*;
import java.net.*;


public class Server {

public static void main(String[] args) {

ServerSocket serverSocket = null;
Socket ss = null;
BufferedReader in = null;
PrintWriter out = null;


try {
serverSocket = new ServerSocket(4444);

ss = serverSocket.accept();
in = new BufferedReader(new
InputStreamReader(ss.getInputStream()));
out = new PrintWriter(ss.getOutputStream());

String bob = null;

while ((bob = in.readLine()) != null)
{
out.println(bob + "from server");
System.out.println(bob);
}
serverSocket.close();
}

catch (IOException e) {
e.printStackTrace();
}
}

}





import java.io.*;
import java.net.*;

public class Client {

public static void main(String[] args) {
Socket socket = null;
PrintWriter out = null;
BufferedReader in = null;
BufferedReader user = null;
try
{
String fromServer, fromUser;

// Connect to server.
socket = new Socket("localhost",4444);

// Out channel.
out = new PrintWriter(socket.getOutputStream());

// In channel.
in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));

// Input from user.
user = new BufferedReader(new InputStreamReader(System.in));

while ((fromServer = in.readLine()) != null)
{
System.out.println(fromServer);
fromUser = user.readLine();

if (fromUser != null)
{
out.println(fromUser);
}
}


}catch(Exception e)
{
System.out.println(e.getMessage());
}
}

}

.



Relevant Pages

  • Re: Java symbol confusion
    ... concepts and things about the java language i don't know, ... The name "serverSocket" is a local variable and that name exists only ... declaration. ... public static void main{ ...
    (comp.lang.java.help)
  • Re: Question:
    ... public static void main(Stringargs) ... //also there should be a boolean method ...
    (comp.lang.java.programmer)
  • Re: When to use float (in teaching)
    ... public class Main ... {public static void main(final java.lang.Stringargs) ... In both cases float and double are working as should be expected. ...
    (comp.lang.java.programmer)
  • Re: list all files on classpath
    ... on the classpath? ... public class Main ... {public static void main(final java.lang.Stringargs) throws java.lang.Throwable ...
    (comp.lang.java.programmer)
  • Re: Hang on socket close after connection reset or connection timed out
    ... public class s { ... public static void main(Stringargs) throws Exception { ...
    (comp.lang.java.programmer)