File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes chat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "chat" Watch "chat" New topic


che sy

Joined: Mar 17, 2003
Posts: 1
I'm creating a project for a single client application in java. what would i do to be able to get the data sent by the client and to transmit data? do you have a sample code for this?
Kathy Sierra
Cowgirl and Author

Joined: Oct 10, 2002
Posts: 1589
You'll need to use Sockets ( package), Streams (, and probably Threads to do this. It's a little too advanced for this forum, though, so I'm just giving you the overview:
Client makes a Socket connection to the server.
Server has a ServerSocket to accept client connections.
Client gets an input stream and output stream from the Socket. Client sends data to the server over the output stream and receives data from the server using the input stream. There are many types of input and output streams, but you might want to look at sending serialized objects using ObjectInputStream and ObjectOutputStream. This can often be eaiser than other streams, but it depends on the kind of data you need to send and receive.
Server does basically the same thing, gets input and output streams from the Socket connection, and sends data and receives data through these streams.
I know there are a couple of books that have chat code in them, but I can't think of the names right now.
good luck,
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Moving this to The Intermediate Forum...
[ March 17, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
You might want to take a look at IBM's Java Chat Server Tutorial.
I agree. Here's the link:
subject: chat
It's not a secret anymore!