Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Socket I/O Question!

Reply
Thread Tools

Socket I/O Question!

 
 
Ken Adams
Guest
Posts: n/a
 
      12-08-2004
Basically all I want to know is that after a client/server is set up using
sockets and say you start by setting the input and output streams to say
PrintWriter(or whatever) can you just go ahead and set the stream to be
another type such as ObjectOuputStream to to send and object? This is of
course assuming both server and client do these steps in the same order.

Basically what I want my client to do is connect to the server, send a
string representing the name of the client then send some Command messages
to the server. Or do you think a better method is to just set up and object
stream and just cast the first object as a string?

Thanks a bunch.


 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      12-08-2004
On Wed, 08 Dec 2004 05:02:21 GMT, Ken Adams wrote:
> Basically all I want to know is that after a client/server is set up
> using sockets and say you start by setting the input and output
> streams to say PrintWriter(or whatever) can you just go ahead and
> set the stream to be another type such as ObjectOuputStream to to
> send and object? This is of course assuming both server and client
> do these steps in the same order.


You can't "set the stream to be another type". You connect streams to
each other to get various types of data conversions.

Don't try to wrap an ObjectOutputStream around any kind of Writer,
which expects *text*. If you want to send Objects, wrap the stream
around an OutputStream, which expects *bytes*.

By the same token, wrap the corresponding ObjectInputStream around an
an InputStream (not a Reader) at the other end.

> Basically what I want my client to do is connect to the server, send
> a string representing the name of the client then send some Command
> messages to the server. Or do you think a better method is to just
> set up and object stream and just cast the first object as a string?


If you only want to send Strings, don't use ObjectStreams at all. Wrap
a Reader and Writer around the InputStream and OutputStream. If you
use a BufferedReader for input, you can easily read the data one line
at a time.

Here is an introduction to this topic:

http://java.sun.com/docs/books/tutor.../overview.html

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments