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?
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 ]
I tried to write a program which read a text file(~300,000 bytes) into a byte array (e.g. byte b=new byte), 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.