Re: socket programming

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: J. Peter Mugaas (oma00215_at_mail.wvnet.edu)
Date: 02/15/04


Date: Sun, 15 Feb 2004 00:44:22 -0500

On Sat, 14 Feb 2004 01:19:18 -0800, Paul Fi wrote:

> i have little knowledge of socket programming, but what i know is that
> using sockets we exchange text between endpoints of the socket but
> first we convert the text to array of bytes and we send it to the other
> side of the comm channel and in the other side we get the original
> string by converting from array of bytes to text
>
> my question is instead of having text exchanged is it possible to have
> objects or complex types converted to array of bytes and vice versa with
> sockets?
>
Yes, you can use an array of bytes and this is what Indy
(http://www.indyproject.org). That passes an array of bytes (TBytes) as a
parameter to the Socket.Send and Socket.SendTo methods (see the DotNET
SDK). In fact, recently, I actually was working on some code in DotNET for
the SNTP protocol (Simple Network Time Protocol) which sits on UDP. That
uses a fixed structure including binary bytes and integers.

I must say something about unsigned word and double-word values. Many
protocols where those are sent in binary should be sent in Network byte
order (not the byte order on your machine or in DotNET). For reading a
binary integer from an endpoint, you would use
IPAddress.HostToNetworkOrder. For sending a binary integer to an endpoint,
you would use IPAddress.HostToNetworkOrder. You often have to do this
with simple UDP query/response protocols or with raw sockets.

HTH.

-- 
J. Peter Mugaas - Indy Pit Crew
Internet Direct (Indy) Website - http://www.nevrona.com/Indy
Personal Home Page - http://www.wvnet.edu/~oma00215
If I want to do business with you, I will contact you.  Otherwise, do not
contact me. 


Relevant Pages

  • Re: Can I use a byte array for sound files?
    ... Sound and sockets are off-topic in comp.lang.c but there are some ... You can read *ANY* readable file into a byte array (well, ... of data from the keyboard, and disk files, but it may be a bit more ...
    (comp.lang.c)
  • Re: File transfer
    ... byte array of that size, ... Ciaran O''Donnell wrote: ... through sockets. ... the receivers end. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: convert fd to IO object in extension?
    ... >>network sockets and disk file I/O. ... Caller creates an instance of Epoll ... add the IO object to a Hash and also call epoll_ctlto add ... that returns, builds an array of 2-cell arrays, the first cell containing ...
    (comp.lang.ruby)
  • Re: size limit for byte array?
    ... Sockets are streaming in nature, and while you might create a 16KB byte ... array on one end and send off using 1 statement, ... Instead of breaking the loop on "less than full buffer", ... on "empty buffer". ...
    (microsoft.public.dotnet.languages.csharp)
  • Mex Pointer initialisation
    ... I would like to step over an array from defined startpoint ... to an endpoint. ...
    (comp.soft-sys.matlab)