permaculture playing cards*
The moose likes Sockets and Internet Protocols and the fly likes Hint needed: TCP -> UDP , test on localhost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Hint needed: TCP -> UDP , test on localhost " Watch "Hint needed: TCP -> UDP , test on localhost " New topic
Author

Hint needed: TCP -> UDP , test on localhost

Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
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

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Sep 17, 2002
Posts: 581
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

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Sep 17, 2002
Posts: 581
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hint needed: TCP -> UDP , test on localhost
 
Similar Threads
DategramPacket and DategramScoket
No buffer space available problem
WS Startup: NET_Bind (in depth, however).
Taming the network problem