Exemple #1
0
        /// <summary>
        /// 出包;
        /// </summary>
        public void SendMessage(int code, object data = null)
        {
            if (offlineSender != null)
            {
                offlineSender.Send(code, data);
                return;
            }

            //如果没有自定义发送器,采用默认方式发送;
            ICommand command = _GetCommand(code);

            if (command != null && command.needWaitResponse)
            {
                if (_lockList.Exists(c => c == code))
                {
                    Debug.Log("协议[" + code.ToString() + "," + command.desc + "]暂时锁定");
                    return;
                }
            }

            if (command != null)
            {
                Debug.Log("Socket send: [" + code.ToString() + "," + command.desc + "]");
                command.WritePackage(data);
                for (int i = 0; i < _sendHandler.Count; i++)
                {
                    _sendHandler[i](code);
                }
            }
        }
Exemple #2
0
        public IListener Verify()
        {
            var socket = _protocolSender.Connect(_hostName, _port);

            if (socket == null)
            {
                //TODO
                throw new InvalidOperationException("Could not connect to the server");
            }

            var isSendTopicSuccessful = _protocolSender.Send(socket, $"Type=subscribe Body={_topic}<EOF>");

            if (!isSendTopicSuccessful)
            {
                //TODO
                throw new InvalidOperationException("Could not subscribe to the topic");
            }

            _serverSocket = socket;

            return(this);
        }
Exemple #3
0
 public void PublishEvent(Socket client)
 {
     _protocolSender.Send(client, "Server to client <EOF>");
 }