This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

chat

 
che sy
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy,
You'll need to use Sockets (java.net package), Streams (java.io), 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,
Kathy
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to The Intermediate Forum...
[ March 17, 2003: Message edited by: Dirk Schreckmann ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to take a look at IBM's Java Chat Server Tutorial.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic