Jump to content
  • Advertisement
Sign in to follow this  
jolyqr

[java] Java and Sockets

This topic is 4295 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Basically I would like to create applications that comunicate by using sockets. I would like to know how I to send an object instead of a text message as those shown in sun tutorials by using sockets ? Cheers !!

Share this post


Link to post
Share on other sites
Advertisement
actually, i saw this method, but i didn't tested it because i don't know how the reciever would decode it...

Share this post


Link to post
Share on other sites
DISCLAIMER: I haven't done this in a long time so I could be off a bit

if you're using a BufferedReader you could use the read() method of it and make it like
in.read((Char [])obj,NULL,sizeof(obj));

Share this post


Link to post
Share on other sites
here is the way i read the recieved message :

while ((inputLine = in.readLine()) != null)
{
recieved.setText(inputLine);
if (inputLine.equals("Bye."))
break;
}

Share this post


Link to post
Share on other sites
Yet another disclamier from me, but shouldnt you be able to wrap the input/output streams of the socket in ObjectInputStream and ObjectOutputStreams ?

Something like

Socket socket = getSocket();
ObjectInputStream objectsIn = new ObjectInputStream( socket.getInputStream() );
ObjectOutputStream objectsOut = new ObjectOutputStream( socket.getOutputStream() );

objectsOut.writeObject( someObject ); // should appear at other end...?




The Objects you send might have to be serializable or something, my java is a bit rusty...

Share this post


Link to post
Share on other sites
I'm quite new in Java. What do you mean by "serializable "? Indeed I have met this word lots of time, but I have never got its meaning...

Share this post


Link to post
Share on other sites
Quote:
Original post by jolyqr
I'm quite new in Java. What do you mean by "serializable "? Indeed I have met this word lots of time, but I have never got its meaning...


If the class implements the interface Serializable then it can be written using ObjectInputStreams to various input streams ( network sockets, files, etc ) and can be retrieved via ObjectOutputStreams. Thats what I remember anyway...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!