//Server receives message from client //Create the peer and send response public void OnRequestConnectToServer(object sender, NetworkMessage message) { NetworkPacket packet = (NetworkPacket)sender; NetworkPeer peer; if (message.header.id == 0) { peer = RegisterPeer(message.header.source); } else { peer = FindPeer(message.header.id); } if (peer == null) { protocol.socket.Failed(NetworkErrorType.ErrorMaxIdentitiesReached, "Peer identity unable to be created.", packet); return; } MessageServer incoming = (MessageServer)message; if (!hasConnected) { hasConnected = true; Console.WriteLine(message.header.source.ToString()); Console.WriteLine(incoming.request.connect.username); } //MessageServer response = protocol.Create<MessageServer>();// message; //response.responseConnected = true; //response.responsePeerId = peer.id; //protocol.SendResponse(message, response); }
public void OnResponseServer(object sender, NetworkMessage message) { NetworkPacket packet = (NetworkPacket)sender; PerformanceTest(); MessageServer msgServer = (MessageServer)message; switch (msgServer.method) { case MessageServer.ServerMethod.CONNECT: Console.WriteLine("Server SendRate (BytesPerFrame) = " + msgServer.response.connect.sendRate); NetworkConfig.ThreadSendSleepPacketSizePerFrame = msgServer.response.connect.sendRate; for (int i = 0; i < NetworkConfig.MAXSEND; i++) { SendHeartbeat(); } break; case MessageServer.ServerMethod.HEARTBEAT: break; } CalculateLatency(); }
public void OnRequestServer(object sender, NetworkMessage message) { PerformanceTest(); MessageServer requestMsg = (MessageServer)message; MessageServer responseMsg = CreateMessage <MessageServer>(); responseMsg.method = requestMsg.method; switch (requestMsg.method) { case MessageServer.ServerMethod.CONNECT: SendIpsum(message.header.source); responseMsg.response.connect.connected = true; responseMsg.response.connect.sendRate = NetworkConfig.ThreadSendSleepPacketSizePerFrame; Console.WriteLine("Setting send rate: {0}", responseMsg.response.connect.sendRate); break; case MessageServer.ServerMethod.HEARTBEAT: break; } SendResponse(requestMsg, responseMsg); }
public void SendHeartbeat() { MessageServer msg = CreateMessage <MessageServer>(); msg.method = MessageServer.ServerMethod.HEARTBEAT; latencyStartTime = NetworkTime.Milliseconds(); SendMessage(server.GetEndpoint(), msg); }
public override MessageServer ConnectToServer(string userName) { MessageServer message = base.ConnectToServer(userName); //SendMessage(server.GetEndpoint(), message); latencyStartTime = NetworkTime.Milliseconds(); SendReliableMessage(server.GetEndpoint(), message); return(message); }
//Client receives response from server public void OnResponseConnectToServer(object sender, NetworkMessage message) { NetworkPacket packet = (NetworkPacket)sender; MessageServer connectMsg = (MessageServer)message; if (local.id == 0) { RegisterLocal(connectMsg.response.connect.peerId, protocol.socket.sendSocket.LocalEndPoint); } }
public NetworkMessage ConnectToServer(string userName) { local.userName = userName; //MsgConnectToServer msg = protocol.Create<MsgConnectToServer>(); MessageServer msg = protocol.Create <MessageServer>(); msg.method = MessageServer.ServerMethod.CONNECT; msg.request.connect.username = userName; return(msg); }