views:

72

answers:

4

Hello all, 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,

A: 

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
A: 

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
A: 

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
A: 

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 ;-)

EJP