Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to send/receive multiple byte array through socket?  RSS feed

 
Ian Wong
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I need to send several byte array(e.g. 1 for public key, 1 for enctypted data) through socket, how can tell the I/O stream that "this is the end of this byte array, i am going to send/receive another one".
Moreover, if I send a byte array with the size > 65535, I get SocketOutputStream exception...is 65535 the limit of socket?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to add some context to the data you are sending. This context is called a "protocol", like FTP or HTTP. The Custom Networking trail of the Java Tutorial has an example of a homemade protocol in the "All About Sockets" section.

is 65535 the limit of socket?

There is no limit to the amount of data a socket can handle. The data transfer is handled by the TCP/IP protocol, so the application need not concern itself with anything but attatching to a port and reading/writing.
The number 65535 may seem significant because computer operating systems specify 65535 ports for programs to use.
[ February 20, 2004: Message edited by: Joe Ess ]
 
Ian Wong
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to write a program which read a text file(~300,000 bytes) into a byte array (e.g. byte[] b=new byte[1000000]), then I get an OutputStream by socket.getOutputStream(), when I tried to write the array to the OutputStream I got a SocketOutputStream Exception. If the array size is smaller than 65,535 then everything is fine.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!