Esempio n. 1
0
        public byte[] Send(byte[] msg)
        {
            try
            {
                if (!Connect())
                {
                    Connect();
                }
                _socket.Send(msg);

                byte[] buffer = new byte[4];
                _socket.Receive(buffer, 4, SocketFlags.None);
                Int32 dataLen = BitConverter.ToInt32(buffer, 0);
                buffer = new byte[dataLen];

                _socket.Receive(buffer, dataLen, SocketFlags.None);


                return(buffer);
            }
            catch (Exception ex) {
                EggLog.Info("send occur error " + ex.Message);
            }
            return(null);
        }
Esempio n. 2
0
        public bool Connect()
        {
            try
            {
                if (_socket == null)
                {
                    throw new Exception("socket is null");
                }

                if (_socket.Connected)
                {
                    return(true);
                }

                _socket.Connect(IPAddress.Parse(_serverAddr), 80);
                if (_socket.Connected)
                {
                    return(true);
                }

                return(false);
            }
            catch (Exception ex) {
                EggLog.Info("socket connect error " + ex.Message);
                return(false);
            }
        }
Esempio n. 3
0
        public static void DoProcess(string action)
        {
            if (!_actionDic.ContainsKey(action))
            {
                throw new Exception("not sport action " + action);
            }
            Action doAction = _actionDic[action];

            try
            {
                doAction();
            }
            catch (Exception ex) {
                EggLog.Info(string.Format("doprocess error {0} {1}", action, ex.Message));
            }
        }