WriteBinary() public method

Write an array of bytes to the socket
public WriteBinary ( byte b ) : uint
b byte
return uint
Exemplo n.º 1
0
        /// <summary>
        /// Transfer data from this socket to the destination socket
        /// until this socket closes
        /// </summary>
        /// <returns>The number of bytes sent</returns>
        public uint TunnelDataTo(HttpSocket dest)
        {
            uint total_sent = 0;

            try
            {
                if (AvailableData == 0)
                {
                    ReadRaw();
                }
                while (AvailableData > 0)
                {
                    uint sent = dest.WriteBinary(Buffer, BufferPosition,
                                                 AvailableData);
                    if (sent < AvailableData)
                    {
                        throw new IoBroken();
                    }
                    total_sent += sent;
                    ReadRaw();
                }
            }
            catch (SocketException) { /* ignore */ }

            return(total_sent);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Transfer data from this socket to the destination socket
        /// until this socket closes
        /// </summary>
        /// <returns>The number of bytes sent</returns>
        public uint TunnelDataTo(HttpSocket dest, System.Threading.CancellationToken cancelToken)
        {
            uint total_sent = 0;

            try
            {
                if (AvailableData == 0)
                {
                    ReadRaw();
                }
                while (AvailableData > 0 && !cancelToken.IsCancellationRequested)
                {
                    uint sent = dest.WriteBinary(Buffer, BufferPosition,
                                                 AvailableData);
                    if (sent < AvailableData)
                    {
                        throw new IoBroken();
                    }
                    total_sent += sent;
                    ReadRaw();
                }
            }
            catch (SocketException) { /* ignore */ }

            return(total_sent);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Tunnel a HTTP-chunked blob of data
 /// </summary>
 /// <param name="dest">The destination socket</param>
 /// <remarks>
 /// The tunneling stops when the last chunk, identified by a
 /// size of 0, arrives. The optional trailing entities are also
 /// transmitted (but otherwise ignored).
 /// </remarks>
 public void TunnelChunkedDataTo(HttpSocket dest)
 {
     TunnelChunkedDataTo(dest, (byte[] b, uint o, uint s) =>
     {
         if (dest.WriteBinary(b, o, s) < s)
         {
             throw new IoBroken();
         }
     });
 }
Exemplo n.º 4
0
 /// <summary>
 /// Read <c>nb_bytes</c> bytes from the socket,
 /// and send it to the destination socket
 /// </summary>
 /// <returns>The number of bytes sent</returns>
 public uint TunnelDataTo(HttpSocket dest, uint nb_bytes)
 {
     return(TunnelDataTo((byte[] b, uint o, uint s) =>
     {
         if (dest.WriteBinary(b, o, s) < s)
         {
             throw new IoBroken();
         }
     }, nb_bytes));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Read <c>nb_bytes</c> bytes from the socket,
 /// and send it to the destination socket
 /// </summary>
 /// <returns>The number of bytes sent</returns>
 public uint TunnelDataTo(HttpSocket dest, uint nb_bytes)
 {
     return TunnelDataTo((byte[] b, uint o, uint s) =>
     {
         if (dest.WriteBinary(b, o, s) < s)
             throw new IoBroken();
     }, nb_bytes);
 }
Exemplo n.º 6
0
        /// <summary>
        /// Transfer data from this socket to the destination socket
        /// until this socket closes
        /// </summary>
        /// <returns>The number of bytes sent</returns>
        public uint TunnelDataTo(HttpSocket dest)
        {
            uint total_sent = 0;

            try
            {
                if (AvailableData == 0)
                    ReadRaw();
                while (AvailableData > 0)
                {
                    uint sent = dest.WriteBinary(Buffer, BufferPosition,
                        AvailableData);
                    if (sent < AvailableData)
                        throw new IoBroken();
                    total_sent += sent;
                    ReadRaw();
                }
            }
            catch (SocketException) { /* ignore */ }

            return total_sent;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Tunnel a HTTP-chunked blob of data
 /// </summary>
 /// <param name="dest">The destination socket</param>
 /// <remarks>
 /// The tunneling stops when the last chunk, identified by a
 /// size of 0, arrives. The optional trailing entities are also
 /// transmitted (but otherwise ignored).
 /// </remarks>
 public void TunnelChunkedDataTo(HttpSocket dest)
 {
     TunnelChunkedDataTo(dest, (byte[] b, uint o, uint s) =>
         {
             if (dest.WriteBinary(b, o, s) < s)
                 throw new IoBroken();
         });
 }
Exemplo n.º 8
0
        /// <summary>
        /// Transfer data from the socket to the specified packet handler with Async Mode
        /// This is Just For A SSL Tunneling
        /// </summary>
        /// <returns>The number of bytes sent</returns>
        public IAsyncResult TunnelDataAsyncTo(HttpSocket dest)
        {
            byte[] buffer = new byte[4096];
            IAsyncResult Result = LowLevelSocket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, new AsyncCallback((ar) =>
                {
                    try
                    {
                        int Ret = (int)ar.AsyncState;

                        Ret = LowLevelSocket.EndReceive(ar);
                        if (Ret > 0)
                        {
                            dest.WriteBinary(buffer, 0, (uint)Ret);
                        }
                        else
                        {
                            CloseSocket();
                        }
                    }
                    catch {  }
                }), new int());
            return Result;
        }