/// <summary> /// 开启服务 /// </summary> /// <returns></returns> public bool StartServer() { asynTcp.AsyncDataAcceptedEvent += AsynTcp_AsyncDataAcceptedEvent; asynTcp.AsyncSocketAcceptEvent += AsynTcp_AsyncSocketAcceptEvent; asynTcp.AsyncSocketClosedEvent += AsynTcp_AsyncSocketClosedEvent; MsgEvent?.Invoke(); StateEvent?.Invoke(string.Format("服务端: {0}:{1} 开始监听!!!", address == "" ? "LocalHost" : address, point.ToString())); return(asynTcp.AsyncOpen()); }
void Update() { lock (recievedMsgs) { if (recievedMsgs.Count > 0) { for (int i = 0; i < recievedMsgs.Count; i++) { messageRecievedEvent.Invoke(recievedMsgs[i]); } recievedMsgs.Clear(); } } }
public bool DispatchMessage(string PlayerName, string Message, bool CheckExist) { if (CheckExist && !HasPlayer(PlayerName)) { return(false); } foreach (OnMessage MsgEvent in OnMessages.ToArray()) { MsgEvent.Invoke(this, PlayerName, Message, Environment.TickCount); } return(true); }
void Update() { lock (recievedMsgs) { if (recievedMsgs.Count > 0) { //Debug.Log("Locked: " + recievedMsgs.Count); for (int i = 0; i < recievedMsgs.Count; i++) { messageRecievedEvent.Invoke(recievedMsgs[i]); } recievedMsgs.Clear(); } } }
public void Update() { lock (_recievedMsgs) { if (_recievedMsgs.Count <= 0) { return; } foreach (var t in _recievedMsgs) { MessageRecievedEvent.Invoke(t); } _recievedMsgs.Clear(); } }
/// Stop requesting when Running=false. protected override void Run() { ForceDotNet.Force(); using (RequestSocket client = new RequestSocket()) { client.Connect("tcp://localhost:5555"); while (Running) { if (Send) { //string message = client.ReceiveFrameString(); client.SendFrame(bytes); string message = null; bool gotMessage = false; while (Running) { gotMessage = client.TryReceiveFrameString(out message); // this returns true if it's successful if (gotMessage) { break; } } if (gotMessage) { // Debug.Log("Received " + message); if (message == "Failed to make plan") { } else { if (msgEvent != null) { msgEvent.Invoke(message); } } } Send = false; } } } NetMQConfig.Cleanup(); }
void Update() { // Receive Messages if (ircStream != null && ircStream.DataAvailable) { buffer = input.ReadLine(); if (buffer != null) { if (buffer.Contains("PRIVMSG #")) { messageReceivedEvent.Invoke(buffer); } if (buffer.StartsWith("PING ")) { SendCommand(buffer.Replace("PING", "PONG")); } if (buffer.Split(' ')[1] == "001") { SendCommand("MODE " + nickName + " +B"); SendCommand("JOIN #" + channelName); } } } //Send messages if (commandQueue.Count > 0) //do we have any commands to send? { // https://github.com/justintv/Twitch-API/blob/master/IRC.md#command--message-limit //have enough time passed since we last sent a message/command? if (lastTimeSentCommand + 0.2f < Time.realtimeSinceStartup) { //send msg. output.WriteLine(commandQueue.Peek()); output.Flush(); //remove msg from queue. commandQueue.Dequeue(); lastTimeSentCommand = Time.realtimeSinceStartup; } } }
void Update() { if (hasBeenConnected) { _onModeratorConnectedEvent.Invoke(); hasBeenConnected = false; } if (hasBeenDisconnected) { _onModeratorDisconnectedEvent.Invoke(); hasBeenDisconnected = false; } lock (recievedMsgs) { if (recievedMsgs.Count > 0) { for (int i = 0; i < recievedMsgs.Count; i++) { messageRecievedEvent.Invoke(recievedMsgs[i]); } recievedMsgs.Clear(); } } }
internal static void SendMsg(string msg) { MsgEvent?.Invoke(msg); }
public static void OnMsgEvent(object sender, BasicDeliverEventArgs e) { MsgEvent?.Invoke(sender, e); }