Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getInputStream

Status
Not open for further replies.

EGONick

Programmer
Apr 13, 2007
2
GB
I'm working on a socket server to instantly receive data from multiple clients, manipulate the data and instantly send it to each of the client connected.

I assumed Java was the simplest as it's the only one I've had minor experiences with.

The problem is, when data is sent, it's stored in the socket until the client disconnects and is then and only then sent to the Java script.

Code:
			DataInputStream in = new DataInputStream(server.getInputStream());
			PrintStream out = new PrintStream(server.getOutputStream());
			
			while((input = in.readLine()) != null)
			{
				System.out.println(input);
			}
			
			System.out.println("[" + new java.text.SimpleDateFormat("HH:mm:ss").format(new java.util.Date()) + "] - Connection closed - ID " + this.clientId);
			server.close();

The server runs fine, clients can connect fine but when data is sent it shows nothing until they disconnect then it's all shown as well as a disconnect message.
 
You are using a readLine() - so unless your incoming data has a CRLF in it ( \r\n ), then you won't see anything till a disconnect.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
That's great, thanks. I've got it working fine.

I'm not having a problem getting the outPutStream working. Is that a similar method using CRLF to show that the data has ended.

I changed it to this.

Code:
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(server.getOutputStream()));

out.write("auth_ok#\r\n");
out.flush();

It still doesn't seem to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top