Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Socket.getInputStream hangs

843790Apr 10 2008 — edited Apr 10 2008
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 8 2008
Added on Apr 10 2008
4 comments
901 views