Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[java] Sockets


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 OneEyeLessThanNone   Members   -  Reputation: 122

Like
Likes
Like

Posted 15 October 2000 - 09:00 AM

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

Sponsor:

#2 Jim_Ross   Members   -  Reputation: 122

Like
Likes
Like

Posted 15 October 2000 - 06:36 PM

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.

#3 bobbin   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 October 2000 - 11:21 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS