コード例 #1
0
 //public TcpCommunicator(string host, int port, OnMessageEvent onMessage) : this(new TcpClient(host, port), onMessage)
 public TcpCommunicator(string host, int port, OnMessageEvent onMessage) : this(new TcpClient(), onMessage)
 {
     Debug.Log(2);
     this.host = host;
     this.port = port;
     ProcessIncomingNetworkData();
 }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="length"></param>
        protected override void OnBytesRead(byte[] buffer, int offset, int length)
        {
            for (var i = offset; i < offset + length; i++)
            {
                m_messageData.WriteByte(buffer[i]);
            }

            do
            {
                if (m_messageLength == -1 && m_messageData.Count > 3)
                {
                    m_messageLength = m_messageData.ReadInt();
                }
                if (m_messageLength != -1 && m_messageId == -1 && m_messageData.Count > 3)
                {
                    m_messageId = m_messageData.ReadInt();
                }
                if (m_messageLength != -1 && m_messageId != -1 && m_messageData.Count >= m_messageLength)
                {
                    var message = MessageBuilder.BuildMessage(m_messageId, m_messageData.ReadBytes(m_messageLength));

                    OnMessageEvent?.Invoke(message);

                    m_messageId     = -1;
                    m_messageLength = -1;
                }
            }while ((m_messageLength == -1 || m_messageId == -1) && m_messageData.Count > 3);
        }
コード例 #3
0
        public TcpCommunicator(TcpClient tcpClient, OnMessageEvent onMessage)
        {
            this.TcpClient = tcpClient ?? throw new ArgumentNullException(nameof(tcpClient));
            this.Name      = $"[{Socket.RemoteEndPoint}]";

            this.mainContext = SynchronizationContext.Current;
            this.OnMessage   = onMessage;
        }
コード例 #4
0
 public void Log(string msg)
 {
     _Messages.Insert(0, new Message()
     {
         Timestamp = DateTime.UtcNow,
         Content   = msg
     });
     OnMessageEvent?.Invoke(this, new Ps2EventArgs <string>(msg));
 }
コード例 #5
0
 protected override void WndProc(ref Message m)
 {
     if (m.Msg == WM_CLOSE)
     {
         Application.ExitThread();
     }
     OnMessageEvent?.Invoke(ref m);
     base.WndProc(ref m);
 }
コード例 #6
0
ファイル: TCPServer.cs プロジェクト: unitycoder/Unity_TCP
        public TCPServer(IPEndPoint endpoint, OnMessageEvent onMessage)
        {
            this.endpoint = endpoint ?? throw new ArgumentNullException("endpoint should not be null");

            // Set Unity main thread
            mainContext = SynchronizationContext.Current;

            OnMessage = onMessage;
        }
コード例 #7
0
 public static void Unregister(OnMessageEvent e)
 {
     foreach (var i in m_Dict_EventRegister)
     {
         if (i.Value.Contains(e))
         {
             i.Value.Remove(e);
         }
     }
 }
コード例 #8
0
 public static void Register(EMessageID msg_id, OnMessageEvent e)
 {
     if (!m_Dict_EventRegister.ContainsKey(msg_id))
     {
         m_Dict_EventRegister.Add(msg_id, new List <OnMessageEvent>());
     }
     if (!m_Dict_EventRegister[msg_id].Contains(e))
     {
         m_Dict_EventRegister[msg_id].Add(e);
     }
 }
コード例 #9
0
        private async Task Start()
        {
            client = new TwitchClient("StylistGraphs", "!", @"oauth:wrkr336oq1airh47j9bpjaggyreuyk", "asmongold");

            var onMessageEvent = new OnMessageEvent();

            onMessageEvent.Register += onMessage;

            var commandHandler = new CommandHandler(onMessageEvent);

            commandHandler.RegisterCommand(new Ping("Ping", "Ping a user"));
            await Task.Delay(-1);
        }
コード例 #10
0
        private void Update()
        {
            if (_messageQueue.Count <= 0)
            {
                return;
            }

            lock (_messageQueue)
            {
                while (_messageQueue.Count > 0)
                {
                    OnMessageEvent?.Invoke(_messageQueue.Dequeue());
                }
            }
        }
コード例 #11
0
            private void Update()
            {
                if (_messageQueue.Count <= 0)
                    return;

                lock (_messageQueue)
                {
                    // Notify about new messages
                    while (_messageQueue.Count > 0)
                    {
                        if (OnMessageEvent != null)
                        {
                            OnMessageEvent.Invoke(_messageQueue.Dequeue());
                        }
                    }
                }
            }
コード例 #12
0
        private void OnEventReceived(SseEvent @event)
        {
            switch (@event.@event)
            {
            case "message":
                OnMessageEvent?.Invoke(@event.jsonData);
                break;

            case "subscription":
                OnSubscriptionEvent?.Invoke(@event.jsonData);
                break;

            case "welcome":
                // do nothing
                // (used by the SseSocket to detect
                // connection establishment)
                break;

            case "heartbeat":
                // do nothing
                break;

            case "end-connection":
                // do nothing
                // (used by the SseSocket to detect
                // server-requested disconnection)
                break;

            default:
                Debug.LogWarning(
                    "[Unisave] Unknown broadcasting event received: " +
                    @event.@event
                    );
                break;
            }
        }
コード例 #13
0
 internal void FireOnMessageEvent(string type, object message)
 {
     OnMessageEvent?.Invoke(type, message);
 }
コード例 #14
0
        //rename stuff

        private static void UdpMessageRecived(string message)
        {
            System.Diagnostics.Debug.WriteLine(message);
            OnMessageEvent.Invoke(message);
        }
コード例 #15
0
 public virtual void OnLidarMessage(string message, int line)
 {
     OnMessageEvent?.Invoke(this, new LidarMessageArgs {
         Value = message, Line = line
     });
 }
コード例 #16
0
 public CommandHandler(OnMessageEvent onMessageEvent)
 {
     onMessageEvent.Register += onMessage;
 }
コード例 #17
0
 public TcpCommunicator(string host, int port, OnMessageEvent onMessage) : this(new TcpClient(host, port), onMessage)
 {
 }
コード例 #18
0
ファイル: TCPServer.cs プロジェクト: unitycoder/Unity_TCP
 public TCPServer(IPEndPoint endpoint, OnMessageEvent onMessage, OnEstablishedEvent onEstablished, OnDisconnectedEvent onDisconnected) : this(endpoint, onMessage)
 {
     OnEstablished  = onEstablished;
     OnDisconnected = onDisconnected;
 }