public ServerConnection(Uri baseAdress) { HubConnection = new HubConnectionBuilder() .WithUrl((new Uri(baseAdress, "/gatheringhub")).AbsoluteUri) .Build(); HubConnection.On <Message>("ReceiveMessage", (message) => OnServerMessage?.Invoke(message)); }
private void ReadPacketQueue() { for (int i = 0; i < messageQueue.Count; i++) { var recv = messageQueue.Dequeue(); ByteUtil.DumpNum(recv.Buffer); OnServerMessage?.Invoke(recv.Buffer); } }
private void OnAsyncData(IAsyncResult ar) { try { Client client = (Client)ar.AsyncState; client.m_length = (ushort)client.m_socket.EndReceive(ar); client.m_data = new byte[client.m_length]; Buffer.BlockCopy(client.m_raw, 0, client.m_data, 0, client.m_length); client.m_raw = null; OnServerMessage?.Invoke(this, client); } catch (Exception e) { HandleException(e); } }