Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

 
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?
 
Bartender
Posts: 9550
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!