   Java sockets, message won't send unless I close the socket
  When I'm sending messages it will not actually send the text unless I close the connection, but I need to send multiple messages back and fourth during a single connection.heres my source:Socket socket = new Socket("localhost", 3333);DataOutputStream o = new DataOutputStream(socket.getOutputStream());o.writeBytes("hello");//closing it is the only way to get it to send, using eithero.close();//orsocket.close()The receiver source is ServerSocket listenSocket = new ServerSocket(3333);BufferedReader inFromConn = new BufferedReader(new InputStreamReader(socket.getInputStream()));while(!inFromConn.ready());System.out.println(inFromConn.readLine()); //isn't called until the connection is closedthanks   
  Isn't DataOutputStream buffered? If so, that'd be your problem. Calling flush() would probably do what you want.   ;  IIRC the Socket class uses a tcp connection, which will be buffered. A flush() call should cause it to send any pending data.Remember that tcp is a stream protocol, not a packet protocol. That means that your "messages" may be split up or merged by the time they reach the other end of your connection. (See Q14 in the network forum faq http://www.gamedev.net/community/forums/showfaq.asp?forum_id=15 ).   ;  The data is probably being buffered. Try calling flush().   ;  I tried flush(), but it did seemingly nothing.edit:I got it working with this:PrintWriter out = new PrintWriter(socket.getOutputStream(), true);out.println("hello");I'm not sure what the difference between the two output clases, but it works how i want.[Edited by - johnnyBravo on September 15, 2007 7:41:34 AM];  Are you really fulshing the right stream? becuase were ever you have a buffer you must flush inorder to get an immidate send. Make sure you call flush on the outer most enclosing stream, otherwise you might as well be doing nothing. And if it doesn't work something is really really wrong.   ;Quote:Original post by johnnyBravoI'm not sure what the difference between the two output clases, but it works how i want.The difference is the newline written by println. The readLine method waits for a newline. If you had used writeBytes("hello\n"), your first example would have worked (I think).