public static void MainX(string[] args) { ServiceHost service = new ServiceHost(NetworkInput.Instance); ServiceEndpoint endpoint = service.AddServiceEndpoint( typeof(XnaSpace.Input.INetworkInputService), new NetTcpBinding(), args[0]); Console.WriteLine(endpoint.ListenUri); service.Open(); Console.WriteLine("Create Another"); Console.ReadLine(); Binding binding = new NetTcpBinding(); EndpointAddress endpointAddress = new EndpointAddress(args[1]); NetworkClient client = new NetworkClient(binding, endpointAddress); client.Open(); using (Space game = new Space(client)) { game.Run(); } try { client.Close(); service.Close(); } catch (Exception) { } }
private void Replicate() { lock (_lock) { try { if (ConnectToHQ()) { SendPackageToHQ(); GetPackageFormHQ(); } } catch (Exception ex) { _log.Error(ex); } finally { if (_client != null) { _client.Close(); _client = null; } } } }
public void Close() { if (m_Client != null) { m_Client.Close(); m_Client = null; } }
public void Stop() { try { RetryTimer.Dispose(); NetworkClient.Close(); } catch { } }
/// <summary> /// Shutdown and cleanup /// </summary> public void Shutdown() { try { // send close packet Packet p = CreatePacket(); p.Command = "_close"; ReturnPacket ret = (ReturnPacket)_client.Send(p); _client.Close(); } catch { } }
public async Task SelectChannel(NetworkClient client, string name) { using (var channelData = await channels.WaitAsync()) { _ = client.SendAsync(new NetworkDataChannelList(channelData.Value)); } NetworkData nd = await client.ReadAsync(); if (nd is NetworkDataChannelSelect sel) { using (var channelData = await channels.WaitAsync()) { if (sel.channel >= MAX_CHANNELS || sel.channel < 0) { client.Close(); return; } else { if (channelData.Value[sel.channel].channelStatus != ChannelStatus.Open) { client.Close(); return; } } } await AddPlayer(new PlayerInfo() { client = client, playerData = new PlayerData() { name = name, channel = sel.channel } }); } else { client.Close(); } }
private static void clientmode() { Console.WriteLine(); NetworkClient nc = new NetworkClient(SERVER_IP, PORT); if (nc.Connect() == false) { Console.WriteLine("Server not available"); return; } string DataToSend = ""; while (DataToSend != "quit") { Console.WriteLine("\nType a text to be sent:"); StringBuilder sb = new StringBuilder(); DataToSend = Console.ReadLine(); if (DataToSend.Length == 0) { continue; } Packet packet = new Packet(); packet.Message = DataToSend; try { nc.Connect(); ReturnPacket ret = nc.Send(packet) as ReturnPacket; if (ret != null) { string returndata = ret.Message; Console.WriteLine("This is what the host returned to you: \r\n{0}", returndata); } else { Console.WriteLine("return null"); } } catch (Exception ex) { Console.WriteLine(ex); return; } } nc.Close(); }
/** * Start as Client. */ static void StartClient() { NetworkClient networkClient = new NetworkClient("127.0.0.1", 7788); Console.WriteLine("End"); while (true) { string command = Console.ReadLine(); if (command == String.Empty) { break; } byte[] messageBytes = Encoding.UTF8.GetBytes(command); networkClient.SendMessage(messageBytes); } networkClient.Close(); }
public void HandleEncryptionResponse(byte[] encryptedSharedSecret, byte[] encryptedSignature) { // "Login request" message not received OR "Encryption response" already received if (_username == null || _signature == null) { return; } var decryptedSignature = Cryptography.CryptoServiceProvider.Decrypt(encryptedSignature, false); if (!decryptedSignature.SequenceEqual(_signature)) { NetworkClient.Close(); return; } _signature = null; _sharedSecret = Cryptography.CryptoServiceProvider.Decrypt(encryptedSharedSecret, false); NetworkClient.EnableEncryption(_sharedSecret); RequestSession(); }
public void StartClient(IPEndPoint serverInfo) { if (IsOnline) { _text.text += $"Cannot Start Client While Online\n"; return; } var ep = serverInfo; _text.text += $"Started Client @ {ep.Address} : {ep.Port}\n"; _client = new NetworkClient(); _client.ClientConnected += ClientOnClientConnected; _client.ClientDisconnected += ClientOnClientDisconnected; _client.MessageReceived += ClientOnMessageReceived; _client.MessageSent += ClientOnMessageSent; if (!_client.TryConnect(serverInfo)) { _text.text += "Killed Client"; _client.Close(); _client = null; } }
/// <summary> /// Shutdown and cleanup /// </summary> public void Shutdown() { _client.Close(); }
public void Close() { Debug.Log("left"); client?.Close(); }
.ContinueWith(task => NetworkClient.Close());
void StartNetwork() { Config config = new Config(); ServiceHost service = new ServiceHost(NetworkInput.Instance); service.AddServiceEndpoint( typeof(XnaSpace.Input.INetworkInputService), new NetTcpBinding(), config.PlayerEndpoint); service.Open(); Binding binding = new NetTcpBinding(); EndpointAddress endpointAddress = new EndpointAddress(config.EnemyEndpoint); NetworkClient client = new NetworkClient(binding, endpointAddress); int tries = 50; while (0 != tries) { try { client.Open(); break; } catch (Exception) { Thread.Sleep(1000); } --tries; } using (Space game = new Space(client)) { game.Run(); } try { client.Close(); service.Close(); } catch (Exception) { } }