public void PerformQuery(string ip, int port) { serverMessage = ""; NetClient client; if (p.EnetAvailable()) { //Create enet client EnetNetClient c = new EnetNetClient(); c.SetPlatform(p); client = c; } else { //Create TCP client TcpNetClient c = new TcpNetClient(); c.SetPlatform(p); client = c; } //Initialize client client.Start(); client.Connect(ip, port); //Do network stuff SendRequest(client); ReadPacket(client); queryPerformed = true; }
public NetServerClient(ushort id, TcpClient tcpClient) { _id = id; // Also store endpoint with TCP address and TCP port _endPoint = (IPEndPoint)tcpClient.Client.RemoteEndPoint; _tcpNetClient = new TcpNetClient(); _tcpNetClient.InitializeWithClient(tcpClient); _tcpNetClient.RegisterOnReceive(OnReceiveData); }
public NetServerClient(ushort id, TcpClient tcpClient, UdpClient udpClient) { _id = id; // Also store endpoint with TCP address and TCP port _endPoint = (IPEndPoint)tcpClient.Client.RemoteEndPoint; _tcpNetClient = new TcpNetClient(); _tcpNetClient.InitializeWithClient(tcpClient); UpdateManager = new ServerUpdateManager(udpClient, _endPoint); }
public NetClient(PacketManager packetManager) { _packetManager = packetManager; _tcpNetClient = new TcpNetClient(); _udpNetClient = new UdpNetClient(); _tcpNetClient.RegisterOnConnect(OnConnect); _tcpNetClient.RegisterOnConnectFailed(OnConnectFailed); // Register the same function for both TCP and UDP receive callbacks _udpNetClient.RegisterOnReceive(OnReceiveData); }
public void ConnectToLoginServer() { tcpNetClient = new TcpNetClient(); tcpNetClient.connectAction += this.OnConnectToLoginServerFinish; tcpNetClient.Connect("127.0.0.1", 5151); }
void Connect(GamePlatform platform) { if (singleplayer) { if (platform.SinglePlayerServerAvailable()) { platform.SinglePlayerServerStart(singleplayerSavePath); } else { serverSimple = new ServerSimple(); DummyNetwork network = platform.SinglePlayerServerGetNetwork(); network.Start(platform.MonitorCreate(), platform.MonitorCreate()); DummyNetServer server = new DummyNetServer(); server.network = network; server.platform = platform; server.Start(); serverSimple.Start(server, singleplayerSavePath, platform); serverSimpleMod = new ModServerSimple(); serverSimpleMod.server = serverSimple; game.AddMod(serverSimpleMod); platform.SinglePlayerServerGetNetwork().ServerReceiveBuffer.Enqueue(new ByteArray()); } connectData = new ConnectData(); connectData.Username = "******"; game.connectdata = connectData; DummyNetClient netclient = new DummyNetClient(); netclient.SetPlatform(platform); netclient.SetNetwork(platform.SinglePlayerServerGetNetwork()); game.main = netclient; } else { game.connectdata = connectData; if (platform.EnetAvailable()) { EnetNetClient client = new EnetNetClient(); client.SetPlatform(platform); game.main = client; } else if (platform.TcpAvailable()) { TcpNetClient client = new TcpNetClient(); client.SetPlatform(platform); game.main = client; } else if (platform.WebSocketAvailable()) { WebSocketClient client = new WebSocketClient(); client.SetPlatform(platform); game.main = client; } else { platform.ThrowException("Network not implemented"); } } }