private void OnClientConnected(object sender, ClientConnectedEventArgs e) { if (this.userService.TryAddUser(e.SessionId, out _)) { this.messageSenderService.NotifyEveryone($"{e.SessionId} has joined.", NotificationLevel.Information); } }
private async void OnClientConnect(object sender, ClientConnectedEventArgs e) { ITcpChannel channel = e.Channel; FreeSwitch freeSwitch = new FreeSwitch(ref channel); try { var added = _clients.TryAdd(channel.ChannelId, freeSwitch); if (added) { await freeSwitch.Connect(); bool ready = await freeSwitch.Resume() && await freeSwitch.MyEvents() && await freeSwitch.DivertEvents(); if (!ready) { await freeSwitch.Close(); return; } } if (ClientReady != null) { ClientReady(this, new InboundClientEventArgs(freeSwitch)); } } catch (Exception) { if (channel != null) { channel.Close(); } } }
private void Listen() { IPEndPoint e = new IPEndPoint(IPAddress.Any, Port); UdpClient server = new UdpClient(e); server.EnableBroadcast = true; byte[] data = new byte[] { 0x00 }; byte[] dataIn = null; while (!tokenSource.IsCancellationRequested) { CancellationTokenSource internalSource = new CancellationTokenSource(); e = new IPEndPoint(IPAddress.Any, Port); Task.Factory.StartNew(() => { dataIn = server.Receive(ref e); messageReceived.Set(); }, internalSource.Token); if (messageReceived.WaitOne(100)) { ClientConnectedEventArgs args = new ClientConnectedEventArgs(e.Address.ToString(), dataIn); ClientConnected?.Invoke(this, args); server.Send(data, 1, e); } internalSource.Cancel(); } }
public async Task Fire_Client_Connected_Event() { using (var testEnvironment = CreateTestEnvironment()) { var server = await testEnvironment.StartServer(); ClientConnectedEventArgs eventArgs = null; server.ClientConnectedAsync += e => { eventArgs = e; return(PlatformAbstractionLayer.CompletedTask); }; await testEnvironment.ConnectClient(o => o.WithCredentials("TheUser")); await LongTestDelay(); Assert.IsNotNull(eventArgs); Assert.IsTrue(eventArgs.ClientId.StartsWith(nameof(Fire_Client_Connected_Event))); Assert.IsTrue(eventArgs.Endpoint.Contains("127.0.0.1")); Assert.AreEqual(MqttProtocolVersion.V311, eventArgs.ProtocolVersion); Assert.AreEqual("TheUser", eventArgs.UserName); } }
protected virtual void OnClientConnectedHandler(ClientConnectedEventArgs e) { var handler = OnClientConnected; if(handler == null) return; handler(this,e); }
/// <summary> /// When a client connects to the DarkRift server /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ClientConnected(object sender, ClientConnectedEventArgs e) { clientsId.Add(e.Client.ID); //Send all objects to spawn SendAllObjectsToSpawnTo(e.Client); }
private void OnClientConnect(object sender, ClientConnectedEventArgs e) { e.Client.MessageReceived += OnMessageReceived; ushort id = playerIDPool.Next(); Player player = new Player(id, Vector3.zero, 0); players.Create(this.NetworkInstantiator.PlayerPrefab, player); ConnectionData data = new ConnectionData(e.Client.ID, enemies.ToArray(), id, levelSeed, players.ToArray()); clientToPlayerObject[data.ClientID] = data.PlayerObjectID; using (Message message = Message.Create(ServerMessage.ConnectionData, data)) { e.Client.SendMessage(message, SendMode.Reliable); } using (Message broadcast = Message.Create(ServerMessage.CreatePlayer, player)) { foreach (var client in Server.Server.ClientManager.GetAllClients()) { if (client.ID != e.Client.ID) { client.SendMessage(broadcast, SendMode.Reliable); } } } }
private void ClientsClientConnect(object sender, ClientConnectedEventArgs e) { IClientInterceptor client = (IClientInterceptor)e.NewClient; this.commandAuthorizations.Add(client, new CommandAuthorization(client, this.commandCollection)); client.Disconnect += this.ClientDisconnect; }
private void ClientConnected(object sender, ClientConnectedEventArgs e) { if (playerManager == null) { playerManager = PluginManager.GetPluginByType <UMPlayerManager>(); } if (entityManager == null) { entityManager = PluginManager.GetPluginByType <UMEntityManager>(); } if (voipManager == null) { voipManager = PluginManager.GetPluginByType <UMVoipManager>(); } UMClient NewClient = new UMClient(e.Client); clients.Add(e.Client, NewClient); Console.WriteLine("WorldManager registered player"); e.Client.MessageReceived += Client_MessageReceived; voipManager.RegisterClient(e.Client); }
private static void ClientConnected(object sender, ClientConnectedEventArgs args) { lastIpPort = args.IpPort; Console.WriteLine("Client connected: " + args.IpPort); // Console.WriteLine("Disconnecting: " + args.IpPort); // server.DisconnectClient(args.IpPort); }
private void OnClientConnected(ClientConnectedEventArgs e) { if (ClientConnected != null) { ClientConnected(this, e); } }
} // End Sub Test static async Task OnClientConnected(object sender, ClientConnectedEventArgs e) { if (!IPAddress.IsLoopback(e.RemoteEndpoint.Address)) { e.RefuseConnect = true; } } // End Function OnClientConnected
private void Events_ClientConnected(object sender, ClientConnectedEventArgs e) { this.Invoke((MethodInvoker) delegate { lstClientIP.Items.Add(e.IpPort); }); }
/// <summary> /// Here all the previously spawned entities are sent to the newly connected client and the IClient reference is added /// to the clients dictionary /// </summary> private void ClientConnected(object sender, ClientConnectedEventArgs e) { using (DarkRiftWriter writer = DarkRiftWriter.Create()) { foreach (ushort client in clientEntitySetLookup.Keys) { foreach (ushort entID in clientEntitySetLookup[client]) { NetworkEntity entity = GetNetworkEntity(entID); writer.Write(entity.owner); writer.Write(entity.id); writer.Write(entity.index); writer.Write(entity.posX); writer.Write(entity.posY); writer.Write(entity.posZ); writer.Write(entity.rotX); writer.Write(entity.rotY); writer.Write(entity.rotZ); } } if (writer.Length > 0) { using (Message m = Message.Create(Tags.spawnObjectWithRotTag, writer)) { e.Client.SendMessage(m, SendMode.Reliable); } } } clientEntitySetLookup.Add(e.Client.ID, new HashSet <ushort>()); e.Client.MessageReceived += SpawnObject; e.Client.MessageReceived += SpawnObjectWithRot; e.Client.MessageReceived += Movement; }
protected virtual void OnClientConnected(ClientConnectedEventArgs e) { if (ClientConnected != null) { ClientConnected(this, e); } }
/// <summary> /// A client has connected (nothing has been sent or received yet) /// </summary> /// <param name="channel">Channel which we created for the remote socket.</param> /// <returns></returns> protected virtual ClientConnectedEventArgs OnClientConnected(ITcpChannel channel) { var args = new ClientConnectedEventArgs(channel); this.ClientConnected(this, args); return(args); }
public void Start() { m_Logger.Log("Starting localhost communication server.", MessageTypeEnum.INFO); IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(LOCALHOST), m_Port); m_Listener = new TcpListener(endPoint); m_Listener.Start(); m_Logger.Log($"Waiting for new connections on port {m_Port}", MessageTypeEnum.INFO); Task task = new Task(() => { while (true) { try { TcpClient client = m_Listener.AcceptTcpClient(); ClientConnectedEventArgs args = new ClientConnectedEventArgs(); args.Client = client; ClientConnected.Invoke(this, args); m_Logger.Log("New connection accepted", MessageTypeEnum.INFO); m_ClientHandler.handleClient(client, m_Controller, m_Logger); m_Logger.Log("QUITING CLIENT", MessageTypeEnum.WARNING); clientDisconnected.Invoke(this, client); } catch (SocketException m_Error) { m_Logger.Log($"Got exception: {m_Error.ToString()}", MessageTypeEnum.INFO); break; } } }); task.Start(); }
private void EventServerConnected(object sender, ClientConnectedEventArgs e) { foreach (ClientView view in views) { view.connected(); } }
private void OnClientConnected(ClientConnectedEventArgs eventArgs) { Console.WriteLine($"server: client connected with ID=[{eventArgs.ClientId}]"); _synchronizationContext.Post(e => ClientConnectedEvent.SafeInvoke(this, (ClientConnectedEventArgs)e), eventArgs); SendMessage("message from server"); }
private void Server_ClientConnected(object sender, ClientConnectedEventArgs e) { clientConnectedTextBox.AppendText(string.Format("New client connected: {0} - At: {1} " , e.ConnectedClient , DateTime.UtcNow , Environment.NewLine)); }
/// <summary> /// Invoked when a new client connects. /// </summary> /// <param name="sender">The client manager.</param> /// <param name="e">The event arguments.</param> void ClientManager_ClientConnected(object sender, ClientConnectedEventArgs e) { //Spawn our new player on all other players Player player = new Player(new Vec3(0, 0, 0), new Vec3(0, 0, 0), e.Client.ID); using (Message message = Message.Create(BlockTags.SpawnPlayer, player)) { foreach (IClient client in ClientManager.GetAllClients()) { if (client != e.Client) { client.SendMessage(message, SendMode.Reliable); } } } lock (players) players.Add(e.Client, player); //Spawn all other players on our new player foreach (IClient client in ClientManager.GetAllClients()) { Player p; lock (players) p = players[client]; using (Message message = Message.Create(BlockTags.SpawnPlayer, p)) e.Client.SendMessage(message, SendMode.Reliable); } //Subscribe to when this client sends messages e.Client.MessageReceived += Client_PlayerEvent; }
void ClientConnected(object sender, ClientConnectedEventArgs e) { Clients.Add(e.Client.ID, e.Client); Console.Write("Insert a message number from 0 to 6 "); SendMessage(int.Parse(Console.ReadLine())); }
private void HandleClientConnected(object sender, ClientConnectedEventArgs e) { e.Client.MessageReceived += _messageHandler.Client_MessageReceived; if (_clients.ContainsKey(e.Client.ID) == false) { if (_clients.Count == maxPlayersCount || gameInProgress) { e.Client.Disconnect(); return; } _clients.Add(e.Client.ID, e.Client); if (_host == null) { _host = e.Client; } using (DarkRiftWriter writer = DarkRiftWriter.Create()) { if (e.Client.ID == _host.ID) { writer.Write(ClientStatus.Host); } else { writer.Write(ClientStatus.Client); } using (Message message = Message.Create(Tags.ConnectionInfo, writer)) { e.Client.SendMessage(message, SendMode.Reliable); } } } }
public static void InvokeClientConnected(ClientConnectedEventArgs e) { if (ClientConnected != null) { ClientConnected(e); } }
private void Events_Connected(object sender, ClientConnectedEventArgs e) { this.Invoke((MethodInvoker) delegate { txtInfo.Text += $"Server connected.{Environment.NewLine}"; }); }
void ClientConnected(object sender, ClientConnectedEventArgs e) { // When client connects, generate new player data Player newPlayer = new Player(e.Client.ID, "default"); players.Add(e.Client, newPlayer); // Write player data and tell other connected clients about this player using (DarkRiftWriter newPlayerWriter = DarkRiftWriter.Create()) { newPlayerWriter.Write(newPlayer); using (Message newPlayerMessage = Message.Create(Tags.PlayerConnectTag, newPlayerWriter)) { foreach (IClient client in ClientManager.GetAllClients().Where(x => x != e.Client)) { client.SendMessage(newPlayerMessage, SendMode.Reliable); } } } // Tell the client player about all connected players foreach (Player player in players.Values) { Message playerMessage = Message.Create(Tags.PlayerConnectTag, player); e.Client.SendMessage(playerMessage, SendMode.Reliable); } UpdatePlayFabPlayers(); // Set client message callbacks e.Client.MessageReceived += OnPlayerInformationMessage; e.Client.MessageReceived += OnPlayerReadyMessage; e.Client.MessageReceived += OnPlayerMoveMessage; }
private void SpawnPlayer(object sender, ClientConnectedEventArgs e) { Random r = new Random(); Player newPlayer = new Player(e.Client.ID, 0, (float)r.NextDouble() * 10f - 5f, (float)r.NextDouble() * 10f - 5f, (float)r.NextDouble() * 10f - 5f); using (DarkRiftWriter writer = DarkRiftWriter.Create()) { writer.Write(newPlayer.id); writer.Write(newPlayer.owner); using (Message m = Message.Create(Tags.spawnPlayerTag, writer)) { foreach (IClient client in players.Keys) { client.SendMessage(m, SendMode.Reliable); } } } players.Add(e.Client, newPlayer); using (DarkRiftWriter writer = DarkRiftWriter.Create()) { foreach (Player player in players.Values) { writer.Write(player.id); writer.Write(player.owner); } using (Message m = Message.Create(Tags.spawnPlayerTag, writer)) { e.Client.SendMessage(m, SendMode.Reliable); } } InitializeClient(e.Client); }
private void Events_Connected(object sender, ClientConnectedEventArgs e) { this.Invoke((MethodInvoker) delegate { txtInfo.Text += $"(Master) Conectado ao servidor. {Environment.NewLine}"; }); }
private void Listen(CancellationToken ct) { Console.WriteLine($"Server started at port {this.Port}"); try { while (true) { var clientTask = this.srv.AcceptTcpClientAsync(); clientTask.Wait(ct); ct.ThrowIfCancellationRequested(); var e = new ClientConnectedEventArgs { Client = clientTask.Result }; Task.Run(async() => await OnClientConnected(e), ct); } } catch (OperationCanceledException) { this.srv.Stop(); } Console.WriteLine($"Server stopped"); }
/// <summary> /// Event handler for new connections to the instance of <see cref="IStreamingServerAsync"/> /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="args">The event arguments</param> private void ClientConnected_EventHandler(object sender, ClientConnectedEventArgs args) { System.Diagnostics.Debug.WriteLine( $@"MessageOperationConfig.ClientConnected_EventHandler() invoked for connection id: {args.ConnectionId}, URL: {Url}", "TransMock.TestMessagingClient"); }
void HandleClientConnected(object sender, ClientConnectedEventArgs ccea) { txtConsole.AppendText(string.Format("{0} - New client connected: {1}{2}", DateTime.Now, ccea.NewClient, Environment.NewLine)); ClientsAmount += 1; clientsAmount.Text = ClientsAmount.ToString(); }
private static void OnClientConnected(object sender,ClientConnectedEventArgs e) { Console.WriteLine("Client [{0}] connected.",((IPEndPoint)e.Client.Socket.RemoteEndPoint).ToString()); e.Client.OnMessageReceived += OnMessageReceived; e.Client.OnClientDisconnected += OnClientDisconnected; client_dictionary.Add(e.Client,(IPEndPoint)e.Client.Socket.RemoteEndPoint); }
private void CreateClient(Socket client) { WebSocketClient wsc = null; //証明書がセットされていたら、 //暗号化モードでクライアントを初期化する。 if(cert == null) { wsc = new WebSocketClient(client); }else{ wsc = new WebSocketClient(client,cert); } wsc.Handshake(); Task.Run(()=> {wsc.Run();}); //接続時のイベント起動 var e = new ClientConnectedEventArgs(); e.Client = wsc; OnClientConnectedHandler(e); }
/// <summary> /// A client has connected (nothing have been sent or received yet) /// </summary> /// <returns></returns> private async void OnClientConnected(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args) { _logger.Debug("Connection from {0}:{1} to {2}:{3} was opened", args.Socket.Information.RemoteHostName.DisplayName, args.Socket.Information.RemotePort, args.Socket.Information.LocalAddress.DisplayName, args.Socket.Information.LocalPort); _logger.Trace("Pipeline => HttpServer.OnClientConnected"); if (args == null || args.Socket == null) return; ClientConnectedEventArgs connectedArgs = new ClientConnectedEventArgs(args); try { ClientConnected(sender, connectedArgs); if (connectedArgs.AllowConnect == false) { if (connectedArgs.Response != null) { await connectedArgs.Response.FlushAsync(); } _logger.Debug("Connection from {0}:{1} to {2}:{3} was denied access to connect", args.Socket.Information.RemoteHostName.DisplayName, args.Socket.Information.RemotePort, args.Socket.Information.LocalAddress.DisplayName, args.Socket.Information.LocalPort); } else { //foreach (var item in httpMessage.Headers) //{ // _logger.Trace("Request Header => {0}:{1}", item.Key, item.Value); //} OnMessageReceived(connectedArgs.Socket); } //args.Socket.Dispose(); //ClientDisconnected(sender, new ClientDisconnectedEventArgs(null, null)); //_logger.Debug("Connection from {0}:{1} to {2}:{3} was closed", // args.Socket.Information.RemoteHostName.DisplayName, // args.Socket.Information.RemotePort, // args.Socket.Information.LocalAddress.DisplayName, // args.Socket.Information.LocalPort); } catch (Exception ex) { // If this is an unknown status it means that the error is fatal and retry will likely fail. if (SocketError.GetStatus(ex.HResult) == SocketErrorStatus.Unknown) { IsActive = false; ListenerError(_listener, ex); _logger.Error("Http request failed with error: {0}", ex.Message, ex); } else { OnClientDisconnected(_listener, ex, SocketError.GetStatus(ex.HResult)); } _logger.Debug("Connection from {0}:{1} to {2}:{3} was {4}", args.Socket.Information.RemoteHostName.DisplayName, args.Socket.Information.RemotePort, args.Socket.Information.LocalAddress.DisplayName, args.Socket.Information.LocalPort, SocketError.GetStatus(ex.HResult).ToString()); } }
/// <summary> /// Löst das <see cref="ClientConnected"/> Ereignis aus. /// </summary> /// <param name="c">Der neu verbundene Remotehost.</param> /// <returns>Die verwendeten Ereignis Argumente.</returns> protected ClientConnectedEventArgs RaiseClientConnected(IClient c) { var myevent = ClientConnected; var args = new ClientConnectedEventArgs(c); if (myevent != null) myevent(this, args); return args; }
/// <summary> /// Handles a client connection. Fires the relevant event and prepares for new connection. /// </summary> private void ClientConnectedHandler(object sender, ClientConnectedEventArgs eventArgs) { OnClientConnected(eventArgs); StartNamedPipeServer(); // Create a additional server as a preparation for new connection }
private void OnClientConnected(object sender, ClientConnectedEventArgs e) { _clients.Add(new StompClient(e.Channel, new TransactionManager())); }
public void HandleClientConnected(DtpNode sender, ClientConnectedEventArgs e) { e.Session.Disconnected += HandleClientDisconnected; transportNode.ClientConnected -= HandleClientConnected; }
void _server_ClientConnected(object sender, ClientConnectedEventArgs args) { App.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => StatusMessages.Add("New client connected."))); }
/// <summary> /// Fires ClientConnectedEvent in the current thread /// </summary> /// <param name="eventArgs"></param> private void OnClientConnected(ClientConnectedEventArgs eventArgs) { _synchronizationContext.Post(e => ClientConnectedEvent.SafeInvoke(this, (ClientConnectedEventArgs) e), eventArgs); }
private static void HandleClientConenct(object sender, ClientConnectedEventArgs e) { e.Client.EnableResponseSystem(); }