public void StopServer() { TransportEventData data = new TransportEventData(); data.type = ENetworkEvent.DisconnectEvent; serverData.Enqueue(data); }
public virtual void OnClientReceive(TransportEventData eventData) { switch (eventData.type) { case ENetworkEvent.ConnectEvent: if (Manager.LogInfo) { Logging.Log(LogTag, "OnPeerConnected"); } Manager.OnClientConnected(); break; case ENetworkEvent.DataEvent: ReadPacket(eventData.connectionId, eventData.reader); break; case ENetworkEvent.DisconnectEvent: if (Manager.LogInfo) { Logging.Log(LogTag, "OnPeerDisconnected peer. disconnectInfo.Reason: " + eventData.disconnectInfo.Reason); } Manager.StopClient(); Manager.OnClientDisconnected(eventData.disconnectInfo); break; case ENetworkEvent.ErrorEvent: if (Manager.LogError) { Logging.LogError(LogTag, "OnNetworkError endPoint: " + eventData.endPoint + " socketErrorCode " + eventData.socketError); } Manager.OnClientNetworkError(eventData.endPoint, eventData.socketError); break; } }
public virtual void OnServerReceive(TransportEventData eventData) { switch (eventData.type) { case ENetworkEvent.ConnectEvent: if (Manager.LogInfo) { Logging.Log(LogTag, "OnPeerConnected peer.ConnectionId: " + eventData.connectionId); } ConnectionIds.Add(eventData.connectionId); Manager.OnPeerConnected(eventData.connectionId); break; case ENetworkEvent.DataEvent: ReadPacket(eventData.connectionId, eventData.reader); break; case ENetworkEvent.DisconnectEvent: if (Manager.LogInfo) { Logging.Log(LogTag, "OnPeerDisconnected peer.ConnectionId: " + eventData.connectionId + " disconnectInfo.Reason: " + eventData.disconnectInfo.Reason); } ConnectionIds.Remove(eventData.connectionId); Manager.OnPeerDisconnected(eventData.connectionId, eventData.disconnectInfo); break; case ENetworkEvent.ErrorEvent: if (Manager.LogError) { Logging.LogError(LogTag, "OnPeerNetworkError endPoint: " + eventData.endPoint + " socketErrorCode " + eventData.socketError + " errorMessage " + eventData.errorMessage); } Manager.OnPeerNetworkError(eventData.endPoint, eventData.socketError); break; } }
public override void OnClientReceive(TransportEventData eventData) { switch (eventData.type) { case ENetworkEvent.ConnectEvent: if (Manager.LogInfo) { Debug.Log("[" + Manager.name + "] LiteNetLibClient::OnPeerConnected"); } Manager.OnClientConnected(); break; case ENetworkEvent.DataEvent: ReadPacket(eventData.connectionId, eventData.reader); break; case ENetworkEvent.DisconnectEvent: if (Manager.LogInfo) { Debug.Log("[" + Manager.name + "] LiteNetLibClient::OnPeerDisconnected peer. disconnectInfo.Reason: " + eventData.disconnectInfo.Reason); } Manager.StopClient(); Manager.OnClientDisconnected(eventData.disconnectInfo); break; case ENetworkEvent.ErrorEvent: if (Manager.LogError) { Debug.LogError("[" + Manager.name + "] LiteNetLibClient::OnNetworkError endPoint: " + eventData.endPoint + " socketErrorCode " + eventData.socketErrorCode); } Manager.OnClientNetworkError(eventData.endPoint, eventData.socketErrorCode); break; } }
private void OnReceiveMessage(TransportEventData eventData) { switch (eventData.type) { case ENetworkEvent.ConnectEvent: //if (LogInfo) Debug.Log("[" + name + "] ::OnPeerConnected peer.ConnectionId: " + eventData.connectionId); PeerConnectedEvent(eventData.connectionId); break; case ENetworkEvent.DataEvent: msgManager.ReadPacket(eventData.connectionId, eventData.reader); break; case ENetworkEvent.DisconnectEvent: if (LogInfo) { Debug.Log("[" + name + "] ::OnPeerDisconnected peer.ConnectionId: " + eventData.connectionId + " disconnectInfo.Reason: " + eventData.disconnectInfo.Reason); } DisconnectedEvent(eventData.connectionId, eventData.disconnectInfo); break; case ENetworkEvent.ErrorEvent: if (LogError) { Debug.LogError("[" + name + "] ::OnNetworkError endPoint: " + eventData.endPoint + " socketErrorCode " + eventData.socketError); } PeerNetworkErrorEvent(eventData.endPoint, eventData.socketError); break; case ENetworkEvent.DiscoveryEvent: //if (LogInfo) Debug.Log("[" + name + "] LiteNetLibServer::DiscoveryEvent endPoint: " + eventData.endPoint); DiscoverServer(eventData.endPoint, eventData.reader.GetString()); break; } }
public void StopClient() { TransportEventData data = new TransportEventData(); data.type = ENetworkEvent.DisconnectEvent; clientData.Enqueue(data); }
public bool ServerReceive(out TransportEventData eventData) { eventData = default(TransportEventData); #if !UNITY_WEBGL || UNITY_EDITOR if (!IsServerStarted) { return(false); } if (!secure) { if (wsServer.EventQueue.Count == 0) { return(false); } return(wsServer.EventQueue.TryDequeue(out eventData)); } else { if (wssServer.EventQueue.Count == 0) { return(false); } return(wssServer.EventQueue.TryDequeue(out eventData)); } #else return(false); #endif }
public bool ClientReceive(out TransportEventData eventData) { eventData = default(TransportEventData); if (client == null) { return(false); } if (dirtyIsConnected != client.IsConnected) { dirtyIsConnected = client.IsConnected; if (client.IsConnected) { // Connect state changed to connected, so it's connect event eventData.type = ENetworkEvent.ConnectEvent; } else { // Connect state changed to not connected, so it's disconnect event eventData.type = ENetworkEvent.DisconnectEvent; } return(true); } else { tempBuffers = client.Recv(); if (tempBuffers != null) { eventData.type = ENetworkEvent.DataEvent; eventData.reader = new NetDataReader(tempBuffers); return(true); } } return(false); }
public bool ServerDisconnect(long connectionId) { TransportEventData data = new TransportEventData(); data.type = ENetworkEvent.DisconnectEvent; serverData.Enqueue(data); return(false); }
public bool ClientSend(byte dataChannel, DeliveryMethod deliveryMethod, NetDataWriter writer) { TransportEventData data = new TransportEventData(); data.type = ENetworkEvent.DataEvent; data.reader = new NetDataReader(writer.CopyData()); clientData.Enqueue(data); return(true); }
public bool ServerSend(long connectionId, byte dataChannel, DeliveryMethod deliveryMethod, NetDataWriter writer) { TransportEventData data = new TransportEventData(); data.type = ENetworkEvent.DataEvent; data.reader = new NetDataReader(writer.CopyData()); serverData.Enqueue(data); return(true); }
public bool StartClient(string address, int port) { clientData.Clear(); TransportEventData data = new TransportEventData(); data.type = ENetworkEvent.ConnectEvent; clientData.Enqueue(data); return(true); }
public bool ClientReceive(out TransportEventData eventData) { eventData = default(TransportEventData); if (serverData.Count == 0) { return(false); } eventData = serverData.Dequeue(); return(true); }
public bool ServerReceive(out TransportEventData eventData) { eventData = default(TransportEventData); if (server == null) { return(false); } server.PollEvents(); if (serverEventQueue.Count == 0) { return(false); } eventData = serverEventQueue.Dequeue(); return(true); }
public bool ClientReceive(out TransportEventData eventData) { eventData = default(TransportEventData); if (client == null) { return(false); } client.PollEvents(); if (clientEventQueue.Count == 0) { return(false); } eventData = clientEventQueue.Dequeue(); return(true); }
public bool ClientReceive(out TransportEventData eventData) { eventData = default(TransportEventData); #if UNITY_WEBGL if (wsClient == null) { return(false); } if (wsDirtyIsConnected != wsClient.IsConnected) { wsDirtyIsConnected = wsClient.IsConnected; if (wsClient.IsConnected) { // Connect state changed to connected, so it's connect event eventData.type = ENetworkEvent.ConnectEvent; } else { // Connect state changed to not connected, so it's disconnect event eventData.type = ENetworkEvent.DisconnectEvent; } return(true); } else { tempBuffers = wsClient.Recv(); if (tempBuffers != null) { eventData.type = ENetworkEvent.DataEvent; eventData.reader = new NetDataReader(tempBuffers); return(true); } } return(false); #else if (client == null) { return(false); } client.PollEvents(); if (clientEventQueue.Count == 0) { return(false); } eventData = clientEventQueue.Dequeue(); return(true); #endif }
public bool ServerReceive(out TransportEventData eventData) { eventData = default(TransportEventData); if (clientData.Count == 0) { return(false); } eventData = clientData.Dequeue(); if (eventData.type == ENetworkEvent.ConnectEvent) { TransportEventData data = new TransportEventData(); data.type = ENetworkEvent.ConnectEvent; serverData.Enqueue(data); peerCount++; } return(true); }
public bool ClientReceive(out TransportEventData eventData) { eventData = default(TransportEventData); #if UNITY_WEBGL return(wsClient.ClientReceive(out eventData)); #else if (Client == null) { return(false); } Client.PollEvents(); if (clientEventQueue.Count == 0) { return(false); } return(clientEventQueue.TryDequeue(out eventData)); #endif }
public bool ServerReceive(out TransportEventData eventData) { eventData = default(TransportEventData); #if !UNITY_WEBGL || UNITY_EDITOR if (!IsServerStarted()) { return(false); } if (serverEventQueue.Count == 0) { return(false); } eventData = serverEventQueue.Dequeue(); return(true); #else return(false); #endif }
public bool Receive(out TransportEventData eventData) { eventData = default(TransportEventData); if (netManager == null) { return(false); } netManager.PollEvents(); if (qEventQueue.Count == 0) { return(false); } eventData = qEventQueue.Dequeue(); return(true); }
public bool ServerReceive(out TransportEventData eventData) { eventData = default(TransportEventData); #if UNITY_WEBGL // Don't integrate server networking to WebGL clients return(false); #else if (wsServer == null || server == null) { return(false); } server.PollEvents(); if (serverEventQueue.Count == 0) { return(false); } eventData = serverEventQueue.Dequeue(); return(true); #endif }
public bool ClientReceive(out TransportEventData eventData) { eventData = default(TransportEventData); #if !UNITY_WEBGL || UNITY_EDITOR if (clientEventQueue.Count == 0) { return(false); } return(clientEventQueue.TryDequeue(out eventData)); #else int eventType = GetSocketEventType(wsNativeInstance); if (eventType < 0) { return(false); } switch ((ENetworkEvent)eventType) { case ENetworkEvent.DataEvent: eventData.type = ENetworkEvent.DataEvent; eventData.reader = new NetDataReader(GetSocketData()); break; case ENetworkEvent.ConnectEvent: eventData.type = ENetworkEvent.ConnectEvent; break; case ENetworkEvent.DisconnectEvent: eventData.type = ENetworkEvent.DisconnectEvent; eventData.disconnectInfo = GetDisconnectInfo(GetSocketErrorCode(wsNativeInstance)); break; case ENetworkEvent.ErrorEvent: eventData.type = ENetworkEvent.ErrorEvent; eventData.errorMessage = GetErrorMessage(GetSocketErrorCode(wsNativeInstance)); break; } SocketEventDequeue(wsNativeInstance); return(true); #endif }
public bool ServerReceive(out TransportEventData eventData) { eventData = default(TransportEventData); #if UNITY_WEBGL // Don't integrate server networking to WebGL clients return(false); #else if (!IsServerStarted) { return(false); } if (!webSocketSecure) { if (wsServer.EventQueue.Count > 0) { return(wsServer.EventQueue.TryDequeue(out eventData)); } } else { if (wssServer.EventQueue.Count > 0) { return(wssServer.EventQueue.TryDequeue(out eventData)); } } Server.PollEvents(); if (serverEventQueue.Count > 0) { return(serverEventQueue.TryDequeue(out eventData)); } return(false); #endif }
public bool ServerReceive(out TransportEventData eventData) { eventData = default(TransportEventData); if (clientData.Count == 0) { return(false); } eventData = clientData.Dequeue(); switch (eventData.type) { case ENetworkEvent.ConnectEvent: TransportEventData data = new TransportEventData(); data.type = ENetworkEvent.ConnectEvent; serverData.Enqueue(data); ServerPeersCount++; break; case ENetworkEvent.DisconnectEvent: ServerPeersCount--; IsClientStarted = false; break; } return(true); }
public bool ClientReceive(out TransportEventData eventData) { return(wsClient.ClientReceive(out eventData)); }
public virtual void OnClientReceive(TransportEventData eventData) { }
public virtual void OnServerReceive(TransportEventData eventData) { }