Errr, UDP is on a lower level that TCP - there's no way to "convert" it to TCP. What, exactly, are you trying to do?
Joined: Mar 18, 2011
Tim Moores wrote:Errr, UDP is on a lower level that TCP - there's no way to "convert" it to TCP. What, exactly, are you trying to do?
as of my knowledge, TCP and UDP are at same level.
actually i am using linux socat command like -
socat -d -T30 -ly UDP4-LISTEN:161,fork,bind=172.16.152.5 TCP4:172.16.152.5:161
now I am doing snmpget for 172.16.152.5 and 161 port for this server is forwarded to another server using ssh (jsch.jar)
now we have to implement socat kind of utility in java.
Joined: Sep 21, 2011
Yes, they're on the same level with respect to ISO/OSI, but TCP has features UDP doesn't - so you can't easily convert a UDP stream to a TCP stream. I'm not sure what socat does, but Java doesn't have access to raw TCP or UDP packets anyway; you'd need to resort to a JNI-based solution.
There are some subtle differences between TCP and UDP, and if they don't concern you, then I see no problems converting from UDP to TCP.
1. UDP is uni-directional. TCP is bi-directional. Since you are going from UDP to TCP, this should not be an issue.
2. UDP is lossy. TCP is not. Again, probably not a concern here.
3. UDP is connection-less. TCP is point to point. Not a problem, if you know that only one sender will be going to a particular address:port; or if you don't care that data may interlace.
4. UDP is datagram based. TCP is "streams" based. Not an issue, if you don't care about the boundaries of the datagrams. Otherwise, you will need to implement some protocol using some sort of delimiter.
Henry Wong wrote:Not sure what you mean by "raw TCP or UDP"
It sounded to me like the task at hand requires munging individual TCP/UDP packets (which can't be done in Java); if that's not necessary then I stand corrected.
Joined: Mar 18, 2011
I do that successfully. thanks for your suggestions.
I create DatagramSocket (udp server)and then receive DatagramPacket and extract payload using DatagramPacket.getData().
create tcp client socket on same port and write the extracted payload and then write on output stream of client socket and flush out stream.
read inputstream into buffer of client socket.
then DatagramPacket fill with buffer.