tags:

views:

102

answers:

3

i am writing program for chat room on client side i had wirtten

clientSocket = new Socket('127.0.0.1',5432);
socketInputBuffer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
socketOutputBuffer = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
systemBuffer = new BufferedReader(new InputStreamReader(System.in));

and on server side

sock = new ServerSocket(5432);

and socketinputbuffer and socketoutputbuffer as written in client

now in above code connection is properly established after that from server side i write in socket stream which i will be reading on the client.

but client waits for server to complete its writing. but when i use shutdownoutput on server it writes and client is able to read properly but same problem occurs when client writes. so i used shutdown output at client also. beacuse of this i am unable to send data next time pls suggest me any method so that client and server should work properly

i am writing using [CODE] socketOutputBuffer.write("Enter Your Name"); socketOutputBuffer.flush(); [/CODE] still not working.

A: 

Here's a quick code sample:

http://www.kieser.net/linux/java_server.html

Wade Tandy
A: 

To send data to the client without closing the connection, use the flush method on BufferedWriter. Also, you need to show how you're doing the reads/writes. You're probably using the blocking methods, in which case the client will wait till it receives data from the server to progress in the thread. You could split the code into two threads - a thread that writes to the server and a thread that reads from the server, or you can use Java NIO. You can use this project as a baseline.

SB
A: 

Try using the flush() method to send data without closing the connection.

Vivin Paliath