コード例 #1
0
 public static void tcpClose(TcpHandler handler)
 {
     try
     {
         if (handler != null)
         {
             handler.Close();
         }
     }
     catch (SocketException e)
     {
         throw new SocketException(e.ErrorCode);
     }
 }
コード例 #2
0
 public static void tcpWrite(TcpHandler handler, Byte[] data)
 {
     try
     {
         if (handler != null)
         {
             if (handler.Client.Connected)
             {
                 handler.Stream.Write(data, 0, data.Length);
             }
         }
     }
     catch (SocketException e)
     {
         throw new SocketException(e.ErrorCode);
     }
 }
コード例 #3
0
        public static TcpHandler tcpOpen(string host, int port)
        {
            TcpClient  client  = new TcpClient(host, port);
            TcpHandler handler = new TcpHandler(client);

            /*
             * try
             * {
             *  handler.Connect(point);
             * }
             * catch (SocketException e)
             * {
             *  throw new SocketException(e.ErrorCode);
             * }
             */
            return(handler);
        }
コード例 #4
0
 public static void tcpWrite(TcpHandler handler, string data)
 {
     try
     {
         if (handler != null)
         {
             Byte[] d = System.Text.Encoding.ASCII.GetBytes(data);
             if (handler.Client.Connected)
             {
                 handler.Stream.Write(d, 0, d.Length);
             }
         }
     }
     catch (SocketException e)
     {
         throw new SocketException(e.ErrorCode);
     }
 }
コード例 #5
0
        public static string tcpRead(TcpHandler handler, int timeOut)
        {
            try
            {
                if (handler != null)
                {
                    if (handler.Client.Connected)
                    {
                        Byte[] buffer = new Byte[2048];
                        handler.Stream.ReadTimeout = timeOut;
                        int bytes = handler.Stream.Read(buffer, 0, buffer.Length);
                        return(System.Text.Encoding.ASCII.GetString(buffer, 0, bytes));
                    }
                }
            }
            catch (SocketException e)
            {
                throw new SocketException(e.ErrorCode);
            }

            return(string.Empty);
        }