binary data through Socket

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.
 
D

Dick Grier

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.
 
G

Guest

if the file is big how do i handle sending chunks data instead of all at once?

mike w.
 
D

Dick Grier

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top