Beispiel #1
0
 public Bind(CenterCmd Command, byte[] _body)
 {
     header        = new Head(Command);
     body          = new Bodys(_body);
     header.Length = (ushort)(Head.HeaderLength + body.Length);
 }
Beispiel #2
0
 public Bind(Head _header, byte[] _body)
 {
     header        = _header;
     body          = new Bodys(_body);
     header.Length = (ushort)(Head.HeaderLength + body.Length);
 }
Beispiel #3
0
        internal static Bind runClient(Bind tbind)
        {
            Bind bind;

            try
            {
                byte[] bit = new byte[tbind.header.Length];
                tbind.ToBytes().CopyTo(bit, 0);
                using (TcpClient client = new TcpClient())
                {
                    //10.237.154.102
#if Debug
                    client.Connect(new IPEndPoint(IPAddress.Parse("192.168.1.17"), 5500));
#endif



#if TEST
                    //  10.237.225.129
                    //client.Connect(new IPEndPoint(IPAddress.Parse("10.105.46.18"), 5500));
                    client.Connect(new IPEndPoint(IPAddress.Parse("10.237.225.129"), 5500));
#endif
#if R17
                    client.Connect(new IPEndPoint(IPAddress.Parse("192.168.1.17"), 5500));
#endif
#if Release
                    //client.Connect(new IPEndPoint(IPAddress.Parse("10.237.154.102"), 5500));
#endif

                    using (NetworkStream stream = client.GetStream())
                    {
                        stream.ReadTimeout = 30000;

                        stream.WriteTimeout = 30000;
                        stream.Write(bit, 0, bit.Length);

                        //List<byte> response = new List<byte>();
                        byte[] ResponseHeadBuffer = new byte[4];
                        int    myResponseLength   = 0;
                        myResponseLength = stream.Read(ResponseHeadBuffer, 0, ResponseHeadBuffer.Length);
                        Head hhh = new Head(ResponseHeadBuffer);

                        byte[] ResponseBodyBuffer = new byte[hhh.Length - 4];
                        if (hhh.Length > 4)
                        {
                            do
                            {
                                myResponseLength = stream.Read(ResponseBodyBuffer, 0, ResponseBodyBuffer.Length);
                            }while (stream.DataAvailable);
                        }

                        bind = new Bind(hhh, ResponseBodyBuffer);
                        stream.Close();
                    }
                    client.Close();
                }
                return(bind);
            }
            catch (Exception error)
            {
                //Bind bind = new Bind(CenterCmd.CS_ACCOUNT_ERROR, new byte[] { });
                return(new Bind(CenterCmd.CS_CONNECT_ERROR, new byte[] { }));

                //throw new Exception(string.Format("ERROR : {0}", error.ToString()));
            }
            return(new Bind(CenterCmd.CS_CONNECT_ERROR, new byte[] { }));
        }