Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hint needed: TCP -> UDP , test on localhost

 
Ellen Zhao
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am to write an EchoClient and an EchoServer. The client should send something to the server with TCP socket. Then the server should echo back the something with UDP socket. Both the user input and the echoed-back would be displayed on client end. This program will be tested on localhost.
I only know how to do it when both the client and server are TCP or UDP. But need some hint about this program. Thank you very much in advance.

Regards,
Ellen
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm failing to understand your question, I think, because I don't see the problem. AFAIK you cannot send datagrams using a Socket, and obviously a DatagramSocket doesn't support TCP/IP, so all you can do is set up a TCP/IP connection for traffic in one direction and a datagram connection in the other.
- Peter
 
Ellen Zhao
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for having made the question vague. I am trying to make it clearer here: The Echoclient sends some string via a connection-oriented Socket(TCP) to the Echoserver. The Echoserver sends the received string via a connectionless( "Verbingdungslos" in the original question)DatagramSocket(I saw in my class notes that User Datagram Protocol is implemented(realisiert) using Datagram Sockets.) back to the Echoclient. The Echolient should display the sent string as well as the echoed string.
It is suggested to run the client and server on different JVMs. I guess so that I can establish the connections on two different ports? Did you mean that? Thanks again.

Regards,
Ellen
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Server opens ServerSocket on some designated port (new ServerSocket(port1)) and listens (accept()). Client opens DatagramSocket on some designated port (new DatagramSocket(port2)). Client connects to server ServerSocket (new Socket(server, port1)) and sends stuff (getOutputStream(), etc). Server creates a DatagramSocket (new DatagramSocket()) and fires its response as a DatagramPacket at the client.
I still feel I'm missing something.
- Peter
 
Ellen Zhao
Ranch Hand
Posts: 581
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to Mr. den Haan, here�s the code:
class Echoserver:

class Echoclient


mit freundlichen Gr��en,
Ellen
[ January 28, 2003: Message edited by: Ellen Fu ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic