Exemple #1
0
        public void SendPacket(GSASendPacket packet)
        {
            packet._Client = this;

            if (!GSOpcode.Send.ContainsKey(packet.GetType()))
            {
                Log.Warn("UNKNOWN GS packet opcode: {0}", packet.GetType().Name);
                return;
            }

            try
            {
                packet.WriteH(GSOpcode.Send[packet.GetType()]); // opcode
                packet.WriteH(0); // packet len
                packet.Write();

                byte[] Data = packet.ToByteArray();
                BitConverter.GetBytes((short)(Data.Length - 4)).CopyTo(Data, 2);

                //if(Configuration.Setting.Debug) Log.Debug("Send: {0}", Data.FormatHex());
                _stream = _client.GetStream();
                _stream.BeginWrite(Data, 0, Data.Length, new AsyncCallback(WriteCallback), (object)null);
            }
            catch (Exception ex)
            {
                Log.Warn("Can't send GS packet: {0}", GetType().Name);
                Log.WarnException("GSASendPacket", ex);
                return;
            }
        }
Exemple #2
0
        public void OnSendButton()
        {
            if (network.IsConnected())
            {
                network.GetStream().Flush();

                SAMPLE.Hello message = new SAMPLE.Hello();
                message.message = "test " + index.ToString();
                index++;
                byte[]        data   = CGSFNet.CGSFNetProtocol.Encode <SAMPLE.Hello>(message, (ushort)SAMPLE.ID.HELLO);
                NetworkStream stream = network.GetStream();
                stream.BeginWrite(data, 0, data.Length, WriteCallback, null);
            }
        }
Exemple #3
0
 public void SendData(Packet packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(packet.ToArray(), 0, packet.Length(), null, null);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error sending data to client {id} via TCP: {e.Message}");
     }
 }
        /// <summary>
        /// Extends BeginWrite so that buffer offset of 0 and call to Array.Length are not needed.
        /// <example>
        /// networkstream.BeginWrite(buffer, callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginWrite(this NetworkStream networkstream, Byte[] buffer, AsyncCallback callback)
        {
            if (networkstream == null)
            {
                throw new ArgumentNullException("networkstream");
            }

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            return(networkstream.BeginWrite(buffer, 0, buffer.Length, callback));
        }
Exemple #5
0
 public void SendData(Packet packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(packet.ToArray(), 0, packet.Length(), null, null);
         }
     }
     catch (Exception e)
     {
         Debug.Log("Error on sending data to host => " + e.ToString());
     }
 }
        public override void SendDataTo(object client, object data)
        {
            _Listener.Server.SendTimeout = 10000;
            byte[]    buff = (byte[])data;
            TcpClient cl   = (TcpClient)client;

            if (!cl.Connected)
            {
                return;
            }
            NetworkStream ns = cl.GetStream();

            ns.BeginWrite(buff, 0, buff.Length, HandleSendDataEnd, cl);
        }
Exemple #7
0
 public void SendAsync(byte[] data)
 {
     m_networkStream.BeginWrite(data, 0, data.Length, ar => {
         try
         {
             NetworkStream networkStream = (NetworkStream)ar.AsyncState;
             networkStream.EndWrite(ar);
         }
         catch (Exception)
         {
             Close();
         }
     }, m_networkStream);
 }
 /// <summary>Sends data to the client via TCP.</summary>
 /// <param name="_packet">The packet to send.</param>
 public void SendData(Packet _packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null); // Send data to server
         }
     }
     catch (Exception _ex)
     {
         Debug.Log($"Error sending data to server via TCP: {_ex}");
     }
 }
        private void WritePartCallback(IAsyncResult asyncResult)
        {
            SendAndReceiveContext context = (SendAndReceiveContext)asyncResult.AsyncState;

            try {
                NetworkStream stream = context.entry.conn.stream;
                stream.EndWrite(asyncResult);
                stream.BeginWrite(context.buf, context.offset, context.length, new AsyncCallback(WriteFullCallback), context);
            }
            catch (Exception e) {
                context.e = e;
                context.callback(asyncResult);
            }
        }
 public void SendData(Packet _packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null);
         }
     }
     catch (Exception _ex)
     {
         Debug.Log($"Error enviando data al jugador {id} a traves de TCP: {_ex}");
     }
 }
Exemple #11
0
 public void SendData(Packet packet)
 {
     try
     {
         if (Socket != null)
         {
             _stream.BeginWrite(packet.ToArray(), 0, packet.Length(), null, null);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error sending data to player {_id} via TCP: {e}");
     }
 }
Exemple #12
0
 public void sendData(Packet _packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null); //note: begin write(converts data to packet to be sent), beginread(revert data to original to be read)
         }
     }
     catch (Exception _e)
     {
         Debug.Log($"Error sending TCP data to player {id} via TCP: {_e}");
     }
 }
Exemple #13
0
 public void SendData(Packet _packet)
 {
     try                     //inside a try catch so that the server does not crash on error
     {
         if (socket != null) //if the socket exists, write to the server
         {
             stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null);
         }
     }
     catch (Exception _ex)
     {
         Debug.Log($"Error sending data to player {id} via TCP: {_ex}");
     }
 }
 /// <summary>
 /// Sends packet through TCP connection
 /// </summary>
 /// <param name="data"></param>
 public void SendPacket(Packet data)
 {
     try
     {
         if (Socket != null)
         {
             stream.BeginWrite(data.ToArray(), 0, data.Length(), null, null);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error sending data via TCP: {ex}");
     }
 }
Exemple #15
0
            /*
             * private void ConnectCallback(IAsyncResult _result)
             * {
             *  try
             *  {
             *      socket.EndConnect(_result);
             *      if (!socket.Connected) return;
             *      IsConnected = true;
             *
             *      receivedData = new Packet();
             *
             *      stream = socket.GetStream();
             *      stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null);
             *  }
             *  catch (Exception e)
             *  {
             *      Disconnect();
             *  }
             * }
             */

            public void SendData(Packet _packet)
            {
                try
                {
                    if (socket != null)
                    {
                        stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null);
                    }
                }
                catch (Exception)
                {
                    // ignored (?) could need to disconnect so [todo]
                }
            }
Exemple #16
0
 public void SendData(Packet _packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null);
         }
     }
     catch (Exception _ex)
     {
         Console.WriteLine($"Error sending data to player {id} via TCP: {_ex}");
     }
 }
Exemple #17
0
 /// <summary>Sends data to the client via TCP.</summary>
 /// <param name="packet">The packet to send.</param>
 public void SendData(Packet packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(packet.ToArray(), 0, packet.Length(), null, null);
         }
     }
     catch (Exception e)
     {
         Log($"Error sending data to server via TCP: {e}.");
     }
 }
Exemple #18
0
 private void aTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     try
     {
         consolelist.Invoke(setListBoxCallback, string.Format("发送信息{0}", controldata.length));
         controldata.encode();
         networkStream.BeginWrite(controldata.databuffer, 0, controldata.length, new AsyncCallback(SendCallback), networkStream);
         networkStream.Flush();
     }
     catch (Exception err)
     {
         consolelist.Invoke(setListBoxCallback, err.Message);
     }
 }
Exemple #19
0
 public void SendData(Packet _packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null);
         }
     }
     catch (Exception e)
     {
         Debug.Log($"发送数据至服务器失败:{e}");
     }
 }
Exemple #20
0
 /// <summary>Sends data to the client via TCP.</summary>
 /// <param name="packet">The packet to send.</param>
 public void SendData(Packet packet)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(packet.ToArray(), 0, packet.Length(), null, null); // Send data to appropriate client
         }
     }
     catch (Exception ex)
     {
         Debug.Log($"Error sending data to player {id} via TCP: {ex}");
     }
 }
Exemple #21
0
        /// <summary>
        /// Writes a producer request to the server asynchronously.
        /// </summary>
        /// <param name="request">The request to make.</param>
        /// <param name="callback">The code to execute once the message is completely sent.</param>
        /// <remarks>
        /// Do not dispose connection till callback is invoked,
        /// otherwise underlying network stream will be closed.
        /// </remarks>
        public void BeginWrite(ProducerRequest request, MessageSent <ProducerRequest> callback)
        {
            this.EnsuresNotDisposed();
            Guard.NotNull(request, "request");
            if (callback == null)
            {
                this.BeginWrite(request);
                return;
            }

            try
            {
                NetworkStream stream = client.GetStream();
                var           ctx    = new RequestContext <ProducerRequest>(stream, request);

                byte[] data = request.RequestBuffer.GetBuffer();

                if (this.socketPollingLevel == SocketPollingLevel.DOUBLE)
                {
                    PollSocket();
                }

                stream.BeginWrite(
                    data,
                    0,
                    data.Length,
                    delegate(IAsyncResult asyncResult)
                {
                    var context = (RequestContext <ProducerRequest>)asyncResult.AsyncState;
                    callback(context);
                    context.NetworkStream.EndWrite(asyncResult);
                },
                    ctx);

                if (this.socketPollingLevel == SocketPollingLevel.SINGLE ||
                    this.socketPollingLevel == SocketPollingLevel.DOUBLE)
                {
                    PollSocket();
                }
            }
            catch (InvalidOperationException e)
            {
                throw new KafkaConnectionException(e);
            }
            catch (IOException e)
            {
                throw new KafkaConnectionException(e);
            }
        }
 protected internal override void SendMessage(NetMessage msg, ReliabilityMode mode)
 {
     msg.WriteSize();
     try
     {
         _stream.BeginWrite(msg.Data, 0, msg.LengthBytes, EndWrite, msg);
     }
     catch (ObjectDisposedException ode)
     {
         if (ode.ObjectName != "System.Net.Sockets.NetworkStream")
         {
             Debug.LogException(ode, $"{ode.ObjectName} disposed when it shouldn't have");
         }
     }
 }
Exemple #23
0
 public void SendData(Packet _packet)
 {
     try
     {
         //If there is an associated TCP client
         if (socket != null)
         {
             stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null); //Send the packet as an array of bytes
         }
     }
     catch (Exception _ex)
     {
         Console.WriteLine("Error sending data to player " + id + " using TCP: " + _ex);
     }
 }
Exemple #24
0
 // Call this function to send the passed in packet to this client over tcp socket
 public void SendData(Packet _packet)
 {
     try
     {
         // Only send the data if the socket is not empty
         if (socket != null)
         {
             stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"Error sending data to player {id} via TCP: {e}");
     }
 }
Exemple #25
0
        public void WriteAsync(NetworkMessage netMessage)
        {
            byte[] buffer = new NetworkMessageFormatter <NetworkMessage>().Serialize(netMessage);

            TcpClient.SendBufferSize = buffer.Length;
            netStream = TcpClient.GetStream();
            if (netStream.CanWrite)
            {
                netStream.BeginWrite(buffer, 0, buffer.Length, writeCallback, netMessage);
            }
            else
            {
                throw new Exception("NetworkStream can not write");
            }
        }
Exemple #26
0
 public void WriteCallback(IAsyncResult result)
 {
     try
     {
         m_stream.EndWrite(result);
         lock (m_writebuflock)
         {
             if (m_writebuf != null)
             {
                 m_stream.BeginWrite(m_writebuf, 0, m_writebuf.Length, WriteCallback, null);
                 m_writebuf = null;
             }
             else if (m_state == State.WaitWrite)
             {
                 m_state = State.Connected;
             }
         }
     }
     catch
     {
         m_error = Error.WriteFailed;
         m_processError(m_error);
     }
 }
Exemple #27
0
 public void SendData(string packet)
 {
     try
     {
         if (socket != null)
         {
             byte[] buffer = Encoding.ASCII.GetBytes(packet);
             stream.BeginWrite(buffer, 0, buffer.Length, null, null);
         }
     }
     catch (Exception _ex)
     {
         Debug.Log($"Error sending data to server via TCP: {_ex}");
     }
 }
Exemple #28
0
        //---- Send
        //---------
        protected void SendNetMessage(NetMessage netMessage)
        {
            if (Status != SharedEnums.ConnectionStatus.Connect)
            {
                Log?.Error($"Connection status: {Status} cannot sent message");
                return;
            }

            NetworkPacket packet = new NetworkPacket();

            if (packet.Write(netMessage))
            {
                stream.BeginWrite(packet.Buffer, 0, packet.Size, SendPacketCallback, null);
            }
        }
Exemple #29
0
 public void SendData(Packet _packet)
 {
     try
     {
         if (socket == null)
         {
             return;
         }
         stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null);
     }
     catch (Exception _ex)
     {
         Console.WriteLine($"Error sendings data to client {id} via TCP: {_ex}");
     }
 }
 public void SendData(Packet _packet)
 {
     try
     {
         if (socket != null)
         {
             _packet.Encrypt(NetworkManager.instance.encryptionType, NetworkManager.instance.encryptionKey);
             stream.BeginWrite(_packet.ToArray(), 0, _packet.Length(), null, null);
         }
     }
     catch (Exception _ex)
     {
         Debug.Log($"Error sending data to player {id} via TCP: {_ex}");
     }
 }
Exemple #31
0
 public void Send(byte[] _bytes)
 {
     try
     {
         if (socket != null)
         {
             stream.BeginWrite(_bytes, 0, _bytes.Length, null, null);
         }
     }
     catch (Exception _ex)
     {
         Logger.LogWarning($"Error sending packet to player {client.id} via TCP: {_ex}");
         //TODO: disconect client
     }
 }
Exemple #32
0
    public void Send(NetBitStream bts, Socket peer)
    {
        NetworkStream ns;
        lock (peer)
        {
            ns = new NetworkStream(peer);
        }

        if (ns.CanWrite)
        {
            try
            {
                ns.BeginWrite(bts.BYTES, 0, bts.Length, new System.AsyncCallback(SendCallback), ns);
            }
            catch (System.Exception)
            {
                PushPacket((ushort)MessageIdentifiers.ID.CONNECTION_LOST, "", peer);
            }
        }
    }
    // 发送消息
    public void Send(NetBitStream bts)
    {
        if (!_socket.Connected)
            return;

        NetworkStream ns;
        lock (_socket)
        {
            ns = new NetworkStream(_socket);
        }

        if (ns.CanWrite)
        {
            try
            {
                ns.BeginWrite(bts.BYTES, 0, bts.Length, new System.AsyncCallback(SendCallback), ns);
            }
            catch (System.Exception)
            {
                PushPacket((ushort)MessageIdentifiers.ID.CONNECTION_LOST, "");
                Disconnect(0);
            }
        }
    }
Exemple #34
0
        /// <summary>
        /// Event for Server Connection
        /// </summary>
        /// <param name="ar"></param>
        private void OnConnectionReady(IAsyncResult ar)
        {
            reconnectTimer.Stop();
            attemptReconnect = true;

            if (serverSocket == null)
            {
                if (ServerError != null)
                    ServerError(this, "Null Socket - Can not Connect", false);
                return;
            }

            try
            {
                serverSocket.EndConnect(ar);
            }
            catch (SocketException se)
            {
                if (ServerError != null)
                    ServerError(this, "Socket Exception Error " + se.ErrorCode + ":" + se.Message, false);

                disconnectError = true;
                ForceDisconnect();
                return;
            }
            catch (Exception e)
            {
                if (ServerError != null)
                    ServerError(this, "Exception Error: " + e.Message, false);

                disconnectError = true;
                ForceDisconnect();
                return;
            }

            socketStream = new NetworkStream(serverSocket, true);

            if (serverSetting.UseSSL)
            {
                try
                {
                    sslStream = new SslStream(socketStream, true, this.RemoteCertificateValidationCallback);
                    sslStream.AuthenticateAsClient(serverSetting.ServerName);
                    ServerMessage(this, "*** You are connected to this server with " + sslStream.SslProtocol.ToString().ToUpper() + "-" + sslStream.CipherAlgorithm.ToString().ToUpper() + sslStream.CipherStrength + "-" + sslStream.HashAlgorithm.ToString().ToUpper() + "-" + sslStream.HashStrength + "bits");
                }
                catch (System.Security.Authentication.AuthenticationException ae)
                {
                    if (ServerError != null)
                        ServerError(this, "SSL Authentication Error :" + ae.Message.ToString(), false);
                }
                catch (Exception e)
                {
                    if (ServerError != null)
                        ServerError(this, "SSL Exception Error :" + e.Message.ToString(), false);
                }
            }

            try
            {
                if (serverSetting.UseSSL)
                {
                    if (sslStream != null && sslStream.CanRead)
                    {
                        readBuffer = new byte[BUFFER_SIZE];
                        sslStream.BeginRead(readBuffer, 0, readBuffer.Length, new AsyncCallback(OnReceivedData), socketStream);
                    }
                }
                else
                {
                    if (socketStream != null && socketStream.CanRead)
                    {
                        readBuffer = new byte[BUFFER_SIZE];
                        socketStream.BeginRead(readBuffer, 0, readBuffer.Length, new AsyncCallback(OnReceivedData), socketStream);
                    }
                }

                this.serverSetting.ConnectedTime = DateTime.Now;

                RefreshServerTree(this);

                if (serverSetting.UseProxy)
                {

                    //socks v5 code
                    byte[] d = new byte[256];
                    ushort nIndex = 0;
                    d[nIndex++] = 0x05;

                    if (serverSetting.ProxyUser.Length > 0)
                    {
                        d[nIndex++] = 0x02;
                        d[nIndex++] = 0x00;
                        d[nIndex++] = 0x02;
                    }
                    else
                    {
                        d[nIndex++] = 0x01;
                        d[nIndex++] = 0x00;
                    }

                    try
                    {
                        socketStream.BeginWrite(d, 0, nIndex, new AsyncCallback(OnSendData), socketStream);

                        if (ServerMessage != null)
                            ServerMessage(this, "Socks 5 Connection Established with " + serverSetting.ProxyIP);
                    }
                    catch (SocketException)
                    {
                        System.Diagnostics.Debug.WriteLine("Error Sending Proxy Data");
                    }
                    catch (Exception)
                    {
                        System.Diagnostics.Debug.WriteLine("proxy exception");
                    }
                }
                else
                {
                    ServerPreConnect(this);

                    if (serverSetting.Password != null && serverSetting.Password.Length > 0)
                        SendData("PASS " + serverSetting.Password);

                    if (serverSetting.UseBNC == true && serverSetting.BNCPass != null && serverSetting.BNCPass.Length > 0)
                        SendData("PASS " + serverSetting.BNCPass);

                    //send the USER / NICK stuff
                    SendData("NICK " + serverSetting.NickName);

                    if (serverSetting.UseBNC == true && serverSetting.BNCUser != null && serverSetting.BNCUser.Length > 0)
                        SendData("USER " + serverSetting.BNCUser + " \"localhost\" \"" + serverSetting.BNCIP + "\" :" + serverSetting.FullName);
                    else
                        SendData("USER " + serverSetting.IdentName + " \"localhost\" \"" + serverSetting.ServerName + "\" :" + serverSetting.FullName);

                    whichAddressinList = whichAddressCurrent;

                    if (serverSetting.UseBNC == true)
                        this.fullyConnected = true;

                    this.pongTimer.Start();
                }
            }

            catch (SocketException se)
            {
                System.Diagnostics.Debug.WriteLine("CODE:" + se.SocketErrorCode);
                System.Diagnostics.Debug.WriteLine("ST:"+ se.StackTrace);

                if (ServerError != null)
                    ServerError(this, "Socket Exception Error:" + se.Message.ToString() + ":" + se.ErrorCode, false);

                disconnectError = true;
                ForceDisconnect();
            }
            catch (Exception e)
            {
                if (ServerError != null)
                    ServerError(this, "Exception Error:" + serverSetting.UseBNC + ":" + e.Message.ToString(), false);

                disconnectError = true;
                ForceDisconnect();
            }
        }
Exemple #35
0
 public void Send(byte[] bytes)
 {
     _stream = _client.GetStream();
     _stream.BeginWrite(bytes, 0, bytes.Length, WriteCallback, null);
 }
        /// <summary>
        /// Envia un mensaje a la red mediante esta maquina remota
        /// </summary>
        /// <param name="netMessage">el mensaje a enviar</param>
        /// <param name="timeOutWriteTCP">el tiempo maximo de espera para el envio</param>
        public void sendNetMessage(NetMessage netMessage, Int32 timeOutWriteTCP)
        {
            lock (sendTCPLock)
            {
                Fails++;
                senderStream = new NetworkStream(TcpClient.Client, false);
                try
                {
                    //senderStream.WriteTimeout = timeOutWriteTCP;
                    byte[] lenght = BitConverter.GetBytes(netMessage.getSize());
                    byte[] netByteMessage = new byte[4 + netMessage.getSize()];

                    IAsyncResult result = senderStream.BeginWrite(lenght, 0, 4, null, null);
                    bool success = result.AsyncWaitHandle.WaitOne(timeOutWriteTCP, false);
                    if (!success)
                    {
                        throw new Exception("TCP: intento de conexión ha tardado demasiado");
                    }
                    else
                    {
                        senderStream.EndWrite(result);
                    }
                    result = senderStream.BeginWrite(netMessage.Body, 0, netMessage.getSize(), null, null);
                    success = result.AsyncWaitHandle.WaitOne(timeOutWriteTCP, false);
                    if (!success)
                    {
                        throw new Exception("TCP: intento de conexión ha tardado demasiado");
                    }
                    else
                    {
                        senderStream.EndWrite(result);
                    }

                    senderStream.Close();
                    Fails = 0;
                }
                catch (ThreadAbortException e)
                {
                    try
                    {
                        senderStream.Close();
                    }
                    catch (Exception)
                    {
                    }
                    throw e;
                }
                catch (Exception)
                {
                    try
                    {
                        senderStream.Close();
                    }
                    catch (Exception)
                    {
                    }
                    throw;
                }
            }
        }
Exemple #37
0
 public void Send(byte[] data, AsyncCallback sentCallback)
 {
     stream = client.GetStream();
     data = AppendLengthByte(data);
     stream.BeginWrite(data, 0, data.Length, sentCallback, stream);
 }
Exemple #38
0
 private void send_motor_serial(NetworkStream clientStream)
 {
     MotorSerial = CLNUIDevice.GetMotorSerial(motor);
     System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
     clientStream.BeginWrite(encoding.GetBytes(MotorSerial), 0, MotorSerial.Length, null, null);
     Console.WriteLine(encoding.GetBytes(MotorSerial).Length);
 }
Exemple #39
0
		public void AsyncWrite ()
		{
			message = "AsyncWrite";
			reset.Reset ();

			NetworkStream ns = new NetworkStream (socket, false);
			byte[] get = Encoding.ASCII.GetBytes ("GET / HTTP/1.0\n\n");
			IAsyncResult r = ns.BeginWrite (get, 0, get.Length, new AsyncCallback (WriteCallback), ns);
			Assert.IsNotNull (r, "IAsyncResult");
			if (!reset.WaitOne (timeout, true))
				Assert.Ignore ("Timeout");
			Assert.IsNull (message, message);
			ns.Close ();
		}
Exemple #40
0
 public void EnviarComando(string comando)
 {
     try {
         //sock.SendTimeout = 3000;
         //sock.ReceiveTimeout = 3000;
         //For iso-8859-1, use Encoding.GetEncoding("iso-8859-1");
         // For ASCII  CP437, use Encoding.GetEncoding(437)
         Encoding enc = Encoding.GetEncoding (437);//*********
         ns = new NetworkStream (sock);
         Console.WriteLine ("Debug: Comando: " + comando);
         //byte[] toSend = Encoding.ASCII.GetBytes(comando);
         byte[] toSend = enc.GetBytes (comando);//**********
         ns.BeginWrite (toSend, 0, toSend.Length, OnWriteComplete, null);
         ns.Flush ();
     } catch (Exception e) {
         Console.WriteLine (e);
     }
 }