Advertisement

[java] Java Socket Protocols

Started by March 03, 2000 01:50 PM
4 comments, last by joeG 24 years, 6 months ago
Which protocol is java.net.Socket based on? I am trying to develop an application-specific protocol. I need to know if I should handle ''packet'' sizes or if the protocol that java.net.Socket is based on should handle packet sizes. As I mentioned in an earlier post, there is no way to control the send/receive buffers in JDK 1.1, so, therefore, the programmer is on their own as far as controlling packet size? Or not?
joeG
Whoa guy, you might need to do some reading on networking before you go writing any network applications. java.net.Socket is a class that represents a socket connection, not a protocol. You make your own protocol by defining a way that a client and server can transmit data through (or over) a socket connection. Generally, protocols are unaware of any transmission packets. And lastly, why not just wrap your socket''s input stream in a buffered reader? so you''d have a buffered socket.... just a thought.
Advertisement
I''m sorry, I meant to ask the question, "Which protocol is java.net.Socket sitting on?" The real question is, "why does sending ''packets'' (''packet'' roughly equals an array full of bytes sent at once) that are larger than X amount of bytes per packet, clog the connection indefinitely (and I mean I''ve waited a lonnnnnnnng time for it to send one of these ''packets'').

And, theoretically, if you''re not able to send more than X amount of bytes over a connection then why should BufferedReader be able to????

Plus the reason I asked about which protocol does java.net.Socket sit on, is because I''m curious to discover if the underlying protocol should''ve handled a ''packet'' of data that was larger than what the buffer could handle. If not, then I should reduce the size of the packets I send through the socket. If so, then I should investigate another part of my program.

Thanks for the help though
joeG
quote: Original post by joeG

I''m sorry, I meant to ask the question, "Which protocol is java.net.Socket sitting on?" The real question is, "why does sending ''packets'' (''packet'' roughly equals an array full of bytes sent at once) that are larger than X amount of bytes per packet, clog the connection indefinitely (and I mean I''ve waited a lonnnnnnnng time for it to send one of these ''packets'').

And, theoretically, if you''re not able to send more than X amount of bytes over a connection then why should BufferedReader be able to????

Plus the reason I asked about which protocol does java.net.Socket sit on, is because I''m curious to discover if the underlying protocol should''ve handled a ''packet'' of data that was larger than what the buffer could handle. If not, then I should reduce the size of the packets I send through the socket. If so, then I should investigate another part of my program.

Thanks for the help though


Umm... I don''t know very much about these protocols, but in most games (I suspect that you are adding this in your game, correct me if I''m wrong) "packet" size is defined by user, he can choose the packet size between Isdn 64k, Isdn 128k, 56k, 33k, 28k, and 14k. And this way packets are optimized for each modem speed. Of course this requires that your protocol can handle these packet sizes

Doh, neverver mind, you asked the protocol and I answered pacets size, I hope this helps someone...


Time comes, time goes and I only am.
First off, wrapping your socket''s input stream in a buffered reader allows it to read more information than it normally can handle and store it for later. You dont'' specifically set packets sizes unless you are working with UDP (I think). TCP/IP guaran-damn-tees that all your information will arrive at it''s destination. Socket and URL classes will use TCP/IP to transmit data. MultiSocket and classes that begin with Datagram use UDP. All of this should be transparent to your program. If it isn''t, you are doing something wrong/very advanced/very uneccasary. If your program just stalls it''s probably because it''s not connecting the socket correctly. You should setSoTimeout(int milliseconds) before you try to read from it. Then the read() will throw an InterruptedIOException. If you check out the client/server example on the networking trail, it doesn''t mention TCP/IP at all.

Don''t confuse network protocols like TCP/IP or UDP with application protocols like HTTP or FTP.
Thanks
joeG

This topic is closed to new replies.

Advertisement