1

I want to implement TCP protocol using Java. I've read Sun documentation and examples but all of them simply open a socket, client waits for server to accept the connection and then sends data.

I wonder how I can implement the three way handshake and data validation using Java? How do server and client exchange sequence number? Does Java provide any class/methods (or at least interface) to implement three way handshake?

Can someone please give me some ideas, or link to some examples?

Thanks in advance,

chepukha
  • 2,371
  • 3
  • 28
  • 40
  • The first thing you should do is accept some answers to your previous questions. People aren't keen on answering questions for which they receive no props. – KevinDTimm Oct 28 '10 at 16:27
  • Thanks for the reminder Kevin. I did not aware of how the system work :( Sorry – chepukha Mar 03 '11 at 17:42

5 Answers5

1

You can't implement TCP in Java as you don't have direct access to the IP layer. Java allows you to work at the transport layer (TCP, UDP), but not at the network layer (IP).

Note that I'm referring to "standard" Java, with the standard Java runtime libraries. There are a few systems out there (typically embedded systems) which use Java for everything, down to the device driver level. I guess this is not what you're after, but just in case, here is a link to a complete TCP/IP stack written in Java for embedded systems:

http://www.jopdesign.com/ejip/index.jsp

Grodriguez
  • 21,501
  • 10
  • 63
  • 107
  • Thank you all for your response. I figure out the problem I need to solve is to work on a specific simulator. So, I'm reading the specification and API for that simulator. But thank you all anyway. – chepukha Nov 04 '10 at 05:19
1

TCP already does all the handshaking and sequence number stuff for you. All you have to do is create a Socket at the client, and a ServerSocket at the server, and accept connections from the ServerSocket. You don't have to implement TCP. It's done. Some time ago ;-)

user207421
  • 305,947
  • 44
  • 307
  • 483
1

Yes it is possible. You can access the IP layer in Java using a library like JPCap. The rest of the TCP implementation can be built by you. This is of course a non-trivial task.

suhridk
  • 238
  • 3
  • 6
0

There's no 'raw' sockets in Sun JDK. You can have access to TCP or UDP or any application-level protocol which is implemented on top of TCP/UDP. Only.

Victor Sorokin
  • 11,878
  • 2
  • 35
  • 51
0

Your question is not completely clear (see other answers inform you that you can't implement TCP in java).

But, what it looks like you want is to implement a protocol over TCP. In that case, the information that you have seen so far is a good starting point. Once you understand communications you can begin to implement a protocol.

Do those things and when you have problems at the protocol level, post your questions (with code) and get help then.

KevinDTimm
  • 14,226
  • 3
  • 42
  • 60