I have a simple client/server app, and the client hangs when I try to get the input stream coming out of the server. I have the following code on the server:
ObjectOutputStream oos = null;
ObjectInputStream ois = null;
port = 49152;
server = new ServerSocket(port, 0, InetAddress.getLocalHost());
sock = server.accept();
oos = new ObjectOutputStream(sock.getOutputStream());
ois = new ObjectInputStream(sock.getInputStream());
String inMsg = (String) ois.readObject();
oos.writeObject(outMsg);
oos.close();
ois.close();
sock.close();
And I try to invoke it with this code on the client:
ObjectOutputStream oos = null;
ObjectInputStream ois = null;
String inMsg = "";
int port = 49152;
try {
Socket sock = new Socket(InetAddress.getLocalHost(), port);
oos = new ObjectOutputStream(sock.getOutputStream());
ois = new ObjectInputStream(sock.getInputStream());//the code hangs here
oos.writeObject(outMsg);
inMsg = (String) ois.readObject();
oos.close();
ois.close();
sock.close();
} catch (Exception e) {
return "";
}
return inMsg;
The code hangs where indicated in the comments. Can someone tell me what I'm doing wrong?
Edited by: MidnightJava on Apr 10, 2008 4:55 AM