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); }
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); } }
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)); } }