[java] Sockets

Started by
1 comment, last by OneEyeLessThanNone 23 years, 6 months ago
I''m writing a simple chat type application, but I cannot send small amouts of data (less than 1024 bytes) at a time. Something is buffering, is there a way i can get the client to just dump what ever i gave it? Doing a flush on the output stream doesnt do anything and setting the send and receive buffers on the socket to smaller numbers isn''t doing anything eather. thanks, onEye
Advertisement
can i see some code from your prog? calling flush does indeed flush the output in my experience. It might be that you aren''t reading the correct length of data and your input socket is waiting for more data.
Setup a client Socket & write an object to the server:
        Socket mySocket = new Socket("myServer.metalabs.net",9999); //your'll need to add you own server domain name & port here <img src="wink.gif" width=15 height=15 align=middle>ObjectOutputStream out = new ObjectOutputStream(mySocket.getOutputStream());out.writeObject(value); //where value is type of any object. //and have the server listen for the client & read the sent object:ServerSocket serverSocket = new ServerSocket(port);Socket mySocket = new Socket(serverSocket.accept()).start();/** *better to fire up a thread like: *new serverThread(serverSocket.accept()).start(); (with no var ref (as written)) *where: public serverThread(Socket socket) { */ObjectInputStream in = new ObjectInputStream((mySocket.getInputStream()));Object retObj = in.readObject();    


Putting things in threads helps, but you shouldn't have any problems with buffers (if you do Socket.setSendBufferSize(int size) may help)...




Edited by - bobbin on October 18, 2000 7:35:19 AM

Edited by - bobbin on October 18, 2000 7:38:20 AM

This topic is closed to new replies.

Advertisement