binary data through Socket

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've got a tcpClient and a tcpListener talking over a socket.
How can I send binary data over the socket from one to the other?

I've got a .jpg in a BinaryReader and I need to send the bytes over the
socket to be rebuilt into a file on the other side.

thanks

mike w.
 
Hi,

You instantiate a BinaryReader, passing it the Stream that you have opened.
The BinaryReader.ReadBytes method will return an array of Byte data.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
 
if the file is big how do i handle sending chunks data instead of all at once?

mike w.
 
Use the BinaryWriter. Assign only as much data to the BinaryWriter (array)
as you want to send at any one time (perhaps 511 bytes to match the default
packet size that is used by TCP/IP?). Then, add a delay between
assignments.

Well, that's what I'd do. Others may have some alternate approach.

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
 
Back
Top