コード例 #1
0
        /// <summary>
        /// Refuse a connection and close the socket
        /// </summary>
        /// <param name="newModel"></param>
        public ReversiClientModel RefuseConnection(ReversiClientModel newModel)
        {
            // And immediately return it without updating the ID
            newModel.CurrentStatus = ConnectionStatusTypes.StatusConnectionRefused;

            try
            {
                DataTransmission.SerializeData <ReversiClientModel>(newModel, newModel.ConnectionSocket);
            }
            catch
            {
                throw new SocketException();
            }

            newModel.ConnectionSocket.Close();

            ClientDisconnectedEventArgs args = new ClientDisconnectedEventArgs
            {
                client = newModel, TimeOfDisconnect = DateTime.Now
            };

            OnClientDisconnected(args);

            return(newModel);
        }
コード例 #2
0
 public static void ClientDisconnected(object sender, ClientDisconnectedEventArgs args)
 {
     window.Dispatcher.Invoke(() =>
     {
         ClientViewObject.Delete(args.IpPort);
     });
 }
コード例 #3
0
 private void Events_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
 {
     this.Invoke((MethodInvoker) delegate
     {
         lstClientIP.Items.Remove(e.IpPort);
     });
 }
コード例 #4
0
 private void EventServerDisconnected(object sender, ClientDisconnectedEventArgs e)
 {
     foreach (ClientView view in views)
     {
         view.disconnected();
     }
 }
コード例 #5
0
 private void ClientDisconnected(object sender, ClientDisconnectedEventArgs args)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         Content.Text += $"Client Disconnect\n\n";
     });
 }
コード例 #6
0
        private void OnClientDisconnected(object sender, ClientDisconnectedEventArgs e)
        {
            SaveCharacterWorldStateInPlayfab(e);

            RemovePlayerFromServer(e);
            SendToAllExcept(e.Client.ID, Tags.DespawnPlayer, new PlayerDespawnData(e.Client.ID));
        }
コード例 #7
0
        private Task handleDisconnection(object sender, ClientDisconnectedEventArgs eventArgs)
        {
            Disconnected?.Invoke(this);
            Log.WriteLine("[NibriClient] Client #{0} disconnected.", Id);

            return(Task.CompletedTask);
        }
コード例 #8
0
 private void DisconnectedEvent(object sender, ClientDisconnectedEventArgs e)
 {
     IsConnected = false;
     InvokeDisconnect();
     Logging.Logger?.LogWarning("[{Function}]:[{PrinterName}] Network printer connection terminated. Attempting to reconnect. Connection String: {ConnectionString}", $"{this}.{MethodBase.GetCurrentMethod().Name}", PrinterName, _settings.ConnectionString);
     Connect();
 }
コード例 #9
0
        public async Task Fire_Client_Disconnected_Event()
        {
            using (var testEnvironment = CreateTestEnvironment())
            {
                var server = await testEnvironment.StartServer();

                ClientDisconnectedEventArgs eventArgs = null;
                server.ClientDisconnectedAsync += e =>
                {
                    eventArgs = e;
                    return(PlatformAbstractionLayer.CompletedTask);
                };

                var client = await testEnvironment.ConnectClient(o => o.WithCredentials("TheUser"));

                await client.DisconnectAsync();

                await LongTestDelay();

                Assert.IsNotNull(eventArgs);

                Assert.IsTrue(eventArgs.ClientId.StartsWith(nameof(Fire_Client_Disconnected_Event)));
                Assert.IsTrue(eventArgs.Endpoint.Contains("127.0.0.1"));
                Assert.AreEqual(MqttClientDisconnectType.Clean, eventArgs.DisconnectType);
            }
        }
コード例 #10
0
ファイル: Form1.cs プロジェクト: JKohlberg/TCPServer-Client
 private void Events_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
 {
     this.Invoke((MethodInvoker) delegate {
         txtInfo.Text += $"{e.IpPort} disconnected.{Environment.NewLine}";
         lbClientIp.Items.Remove(e.IpPort);
     });
 }
コード例 #11
0
 private void OnClientDisconnected(ClientDisconnectedEventArgs e)
 {
     if (ClientDisconnected != null)
     {
         ClientDisconnected(this, e);
     }
 }
コード例 #12
0
        private static void Networker_Disconnected(object sender, ClientDisconnectedEventArgs e)
        {
            string reason = e.Reason;

            if (string.IsNullOrWhiteSpace(reason))
            {
                reason = ". No reason given.";
            }
            else
            {
                reason = ": " + reason;
            }

            if (CupboardApp.Networker.Hosting)
            {
                OldContext.ShowNotification("Info", e.RemoteEndPoint + " left the server.", duration: 3);
            }
            else
            {
                string type = reason == "Quit" ? "Info" : "Error";

                OldContext.ShowNotification(type, "Disconnected from server" + reason, duration: 3, channel: "Main");
                Scene.SwitchTo(_menuScene);
            }
        }
コード例 #13
0
ファイル: AppManament.cs プロジェクト: pnt239/DADHMT_LTW
        void Client_DisconnectedFromServer(object sender, ClientDisconnectedEventArgs eventArgs)
        {
            _clientList.Clear();
            _sendList.Clear();

            OnDisconnected(EventArgs.Empty);
        }
コード例 #14
0
ファイル: TCPServer.cs プロジェクト: youssefcoder/TempestCore
        protected void ClientDisconncted(object sender, ClientDisconnectedEventArgs e)
        {
            RaiseClientDisconnected(e);
            TcpSession session;

            _sessions.TryRemove(e.Session.Guid, out session);
        }
コード例 #15
0
        internal async Task Server_ClientDisconnected(ClientDisconnectedEventArgs args)
        {
            try
            {
                var dev = await FoundDevice(args.ClientId);

                if (dev != null)
                {
                    using (var scope = _scopeFactor.CreateScope())
                        using (var _dbContext = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>())
                        {
                            var devtmp = _dbContext.Device.FirstOrDefault(d => d.Id == dev.Id);
                            devtmp.LastActive = DateTime.Now;
                            devtmp.Online     = false;
                            await _dbContext.SaveChangesAsync();

                            _logger.LogInformation($"Server_ClientDisconnected   ClientId:{args.ClientId} DisconnectType:{args.DisconnectType}  Device is {devtmp.Name }({devtmp.Id}) ");
                        }
                }
                else
                {
                    _logger.LogWarning($"Server_ClientDisconnected ClientId:{args.ClientId} DisconnectType:{args.DisconnectType}, 未能在缓存中找到");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Server_ClientDisconnected ClientId:{args.ClientId} DisconnectType:{args.DisconnectType},{ex.Message}");
            }
        }
コード例 #16
0
        private void OnDisconnect(object sender, ClientDisconnectedEventArgs e)
        {
            Server.DisconnectPeer(this);
            var userData = (UserData)clientData[typeof(UserData)];

            Console.WriteLine($"User {userData.Id} left the game.");
        }
コード例 #17
0
 private void OnClientDisconnect(object sender, ClientDisconnectedEventArgs e)
 {
     if (isLoadingTrain)
     {
         CheckIfAllPlayersLoadedTrain();
     }
 }
コード例 #18
0
 private void Events_Disconnected(object sender, ClientDisconnectedEventArgs e)
 {
     this.Invoke((MethodInvoker) delegate
     {
         txtInfo.Text += $"(Master) Servidor Desconectado. {Environment.NewLine}";
     });
 }
コード例 #19
0
ファイル: TCPSession.cs プロジェクト: afii369/FagNet
 private void RaiseDisconnected(ClientDisconnectedEventArgs e)
 {
     if (Disconnected != null)
     {
         Disconnected(this, e);
     }
 }
コード例 #20
0
 private void OnDisconnectedFromServer(ClientDisconnectedEventArgs e)
 {
     if (DisconnectedFromServer != null)
     {
         DisconnectedFromServer(this, e);
     }
 }
コード例 #21
0
        private void ClientManager_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
        {
            pendingConnections.RemoveAll(x => x == e.Client.ID);

            e.Client.MessageReceived -= Client_MessageReceived;
            LeaveRoom(e.Client.ID);
        }
コード例 #22
0
        void ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
        {
            players.Remove(e.Client);

            using (DarkRiftWriter writer = DarkRiftWriter.Create())
            {
                writer.Write(e.Client.ID);

                using (Message message = Message.Create(DESPAWN_TAG, writer))
                {
                    foreach (IClient client in ClientManager.GetAllClients())
                    {
                        client.SendMessage(message, SendMode.Reliable);
                    }
                }
            }

            if (players.Count == 0)
            {
                testTrain = null;
                objects.Clear();
                IDCounter = 0;
                InitializeTrain();
                InitializeObjects();

                gameStarted = false;
            }
        }
コード例 #23
0
        private void ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
        {
            entityManager.UnregisterClient(e.Client);
            playerManager.UnregisterClient(e.Client);

            this.clients.Remove(e.Client);
        }
コード例 #24
0
 //--------------------------------------------------------------
 // METHODE DECONNECTION
 //--------------------------------------------------------------
 private void Events_Disconnected(object sender, ClientDisconnectedEventArgs e)   //on reçoit la source et les données d'évènement
 {
     this.Invoke((MethodInvoker) delegate                                         //si la deconnection est sur le thread principal
     {
         txtInfo.Text += $"Server disconnected.{Environment.NewLine}";            //ecriture:Server disconnected
     });
 }
コード例 #25
0
        private void ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
        {
            e.Client.MessageReceived -= SpawnObject;
            e.Client.MessageReceived -= SpawnObjectWithRot;
            e.Client.MessageReceived -= Movement;

            using (DarkRiftWriter writer = DarkRiftWriter.Create())
            {
                foreach (ushort entID in clientEntitySetLookup[e.Client.ID])
                {
                    writer.Write(entID);
                    entityCount--;
                    freeID.Enqueue(entID);
                    networkEntities.Remove(entID);
                }
                using (Message message = Message.Create(Tags.destroyObjectTag, writer))
                {
                    foreach (IClient client in ClientManager.GetAllClients())
                    {
                        client.SendMessage(message, SendMode.Reliable);
                    }
                }
            }


            clientEntitySetLookup.Remove(e.Client.ID);
        }
コード例 #26
0
 private void OnClientDisconnected(object sender, ClientDisconnectedEventArgs e)
 {
     if (this.userService.TryRemoveUser(e.SessionId))
     {
         this.messageSenderService.NotifyEveryone($"{e.SessionId} has left.", NotificationLevel.Information);
     }
 }
コード例 #27
0
 private void UnRegisterClient(object sender, ClientDisconnectedEventArgs e)
 {
     e.Client.MessageReceived -= ClientAuthRequest;
     if (loggedInCharacters.ContainsKey(e.Client))
     {
         LogoutClient(e.Client);
     }
 }
コード例 #28
0
        private void ClientDisconnectedHandler(object sender, ClientDisconnectedEventArgs eventArgs)
        {
            _synchronizationContext.Post(
                e => ClientDisconnectedEvent?.Invoke(this, (ClientDisconnectedEventArgs)e),
                eventArgs);

            StopNamedPipeServer(eventArgs.ClientId);
        }
コード例 #29
0
 private void OnClientDisconnected(object sender, ClientDisconnectedEventArgs e)
 {
     Logger.Info("Goodbye " + e.Client.ID);
     if (pendingPlayer != null && pendingPlayer.Client == e.Client)
     {
         pendingPlayer = null;
     }
 }
コード例 #30
0
        protected override void OnDisconnected(ClientDisconnectedEventArgs e)
        {
            base.OnDisconnected(e);

            Persona.Status = Status.Offline;

            Task.Run(() => Reconnect());
        }
コード例 #31
0
ファイル: echotest.cs プロジェクト: Carrot031/websocket-cs
	public static void OnClientDisconnected(object sender,ClientDisconnectedEventArgs e)
	{
		var client = (WebSocketClient) sender;

		//client.Socket.RemoteEndPointはアクセスできない(ソケットは閉じられている)ため、
		//各自でIPEndPointを保管する必要がある。
		//Because client.Socket.RemoteEndPoint is inaccecible,
		//you need to store IPEndPoint yourself.
		var ipendpoint = client_dictionary[client];
		Console.WriteLine("Client [{0}] disconnected.",ipendpoint.ToString());
	}
コード例 #32
0
        private void OnClientDisconnect(object sender, ClientDisconnectedEventArgs e) {
            ITcpChannel channel = e.Channel;
            Exception exception = e.Exception;
            FreeSwitch freeSwitch;
            if (exception != null) {
                if (_clients.TryGetValue(channel.ChannelId, out freeSwitch)) freeSwitch.Error(channel, exception);
                return;
            }

            try { _clients.TryRemove(channel.ChannelId, out freeSwitch); }
            catch (ArgumentNullException) {
                // ignored
            }
        }
コード例 #33
0
        /// <summary>
        /// Hanldes a client disconnection. Fires the relevant event ans removes its server from the pool
        /// </summary>
        private void ClientDisconnectedHandler(object sender, ClientDisconnectedEventArgs eventArgs)
        {
            OnClientDisconnected(eventArgs);

            StopNamedPipeServer(eventArgs.ClientId);
        }
コード例 #34
0
	public void Run()
	{
		Debug.WriteLine("やあ。");
		stream.ReadTimeout = -1;
		Debug.WriteLine("WFD");

		var message_data = new List<byte>();
		var fragment_data = new List<byte>();
		WebSocketFragmentOpcode? current_fragment_type = null;
		WebSocketFragmentInfo fragment_info = null; //ダウンロード中のフラグメント情報
		while(true)
		{
			try
			{
				byte[] buf = new byte[4096];
				//client.Poll(-1,SelectMode.SelectRead);
				int cycle_received = stream.Read(buf,0,buf.Length);

				if(cycle_received == 0)
				{//切断時
					break;
				}
				Debug.WriteLine("RECEIVED {0} bytes",cycle_received);
				for(int i=0;i<cycle_received;i++)
				{
					Debug.WriteLine(buf[i].ToString());
				}

				//-----データ解析-----
				int read_num_bytes = 0;
				while(cycle_received - read_num_bytes > 0)
				{
					if(fragment_info == null)
					{
						//フラグメントの必須ヘッダがない場合
						//(fragment_data.Count < 2)
						int to_read = cycle_received - read_num_bytes>= 2 ?
						2 - fragment_data.Count
						: cycle_received - read_num_bytes;

						for(int i=0; i<to_read; i++)
						{
							//最大で2バイト読み取り
							fragment_data.Add(buf[read_num_bytes + i]);
						}
						read_num_bytes += to_read; //読み取ったバイト数を反映
						
						if(fragment_data.Count == 2)
						{
							//2バイトの必須ヘッダがある状態
							fragment_info = 
							WebSocketFragmentInfo.
							FromNecessary2Bytes(fragment_data.ToArray());
							Debug.WriteLine("HEADERSIZE:"+fragment_info.CalculateSizeOfInfo().ToString());
						}else{
							//受信データ不足
							break;
						}

					}
					
					if(fragment_info != null)
					{
						//フラグメントの必須ヘッダがある

						//拡張ヘッダも含めたヘッダの長さ
						int header_len = fragment_info.CalculateSizeOfInfo();
						if(fragment_data.Count < header_len)
						{
							//ヘッダの長さが足りない
							//つまり未受信 or 未読

							int shortage = header_len - fragment_data.Count; //不足分
							int to_read = cycle_received - read_num_bytes >= shortage ?
							shortage
							: cycle_received - read_num_bytes;

							for(int i=0; i< to_read; i++)
							{
								//最大でshortageバイト読み取り
								fragment_data.Add(buf[read_num_bytes + i]);
							}
							read_num_bytes += to_read; //読み取ったバイト数を反映


							if(fragment_data.Count == header_len)
							{
								//ヘッダをすべてダウンロードできた

								fragment_info = WebSocketFragmentInfo.FromBinary(fragment_data.ToArray());
								Debug.WriteLine("PAYLOADSIZE:"+fragment_info.PayloadLength);

								
								if(fragment_info.Opcode == WebSocketFragmentOpcode.Continuation)
								{	
									//前フレームの続きと言っている場合

									if(current_fragment_type == null)
									{
										//前のフレームがない
										throw new Exception("Opcode is continuation but no former frame.");
									}
								}else{
									current_fragment_type = fragment_info.Opcode;
								}
							}else{
								//受信データ不足
								break;
							}
						}
						

						if(fragment_data.Count >= header_len)
						{
							//ヘッダは読み込み済み
							//Payloadを読み込む。

							int shortage = 
							(int)fragment_info.PayloadLength -
							fragment_data.Count +
							header_len; //不足分
							int to_read = cycle_received - read_num_bytes >= shortage ?
							shortage
							: cycle_received - read_num_bytes;
							Debug.WriteLine("COUNT:"+fragment_data.Count.ToString());
							Debug.WriteLine("HEADER_LEN:"+header_len.ToString());
							Debug.WriteLine("SHORTAGE_PAYLOAD:"+shortage.ToString());

							for(uint i=0; i< to_read; i++)
							{
								//最大でshortageバイト読み取り
								fragment_data.Add(buf[read_num_bytes + i]);
							}
							read_num_bytes += to_read; //読み取ったバイト数を反映

							if(fragment_data.Count == header_len + (int)fragment_info.PayloadLength)
							{
								//Payloadをすべてダウンロードできた
								Debug.WriteLine("FRAGMENT CLOSE");

								byte[] decoded = new byte[fragment_data.Count];
								for(int i = header_len; i < fragment_data.Count; i++)
								{
									//受信したペイロードをデコード(unmask)
									decoded[i - header_len] = (byte)(fragment_data[i] ^ 
									fragment_info.MaskingKey[(i - header_len) % 4]);
								}
								//メッセージにプッシュ
								message_data.AddRange(decoded);

								if(fragment_info.Opcode == WebSocketFragmentOpcode.ConnectionClose)
								{
								
									//切断しろと言ってきた
									var closing_ep = (IPEndPoint)Socket.RemoteEndPoint;
									Debug.WriteLine("Closing connection was requested by [{0}]"
									,closing_ep.ToString());
									
									//切断する。
									this.Disconnect();

									Debug.WriteLine("Connection to [{0}] was closed.",closing_ep.ToString());
									//切断時イベント
									var e = new ClientDisconnectedEventArgs();
									//e.IPEndPoint = closing_ep;
									OnClientDisconnectedHandler(e);
									return;
								}else{
									Debug.WriteLine("OPCODE:"+fragment_info.Opcode.ToString());
								}

								if(fragment_info.FIN)
								{
									//メッセージの終わり。

									Debug.WriteLine("MESSAGE END");

									//メッセージの受信完了イベントを起動する
									var e = new MessageReceivedEventArgs();
									//e.IPEndPoint = (IPEndPoint) Socket.RemoteEndPoint;
									e.DecodedMessage = message_data.ToArray();
									OnMessageReceivedHandler(e);

									//メッセージを破棄
									message_data.Clear();
								}

								fragment_data.Clear();
								fragment_info = null;
								current_fragment_type = null;
							}else{
								//受信データ不足
								break;
							}
						}



					}
				}
				
				if(cycle_received - read_num_bytes != 0)
				{
					Debug.WriteLine("尿漏れ");
				}

				

				Debug.WriteLine("---------");
			}catch(SocketException){
				Debug.WriteLine("[{0}] SocketException occured.",((IPEndPoint)Socket.RemoteEndPoint).ToString());
			}
		}
	}
コード例 #35
0
ファイル: Program.cs プロジェクト: pushtechnology/cloud
 private void clientDisconnected(object sender, ClientDisconnectedEventArgs arg0)
 {
     System.Console.WriteLine("Client DisConnected");
 }
コード例 #36
0
	protected virtual void OnClientDisconnectedHandler(ClientDisconnectedEventArgs e)
	{
		var handler = OnClientDisconnected;
		if(handler == null) return;
		handler(this,e);
	}
コード例 #37
0
 public void InvokeClientDisconnected(ClientDisconnectedEventArgs ca)
 {
     ClientDisconnectedEvent handler = ClientDisconnected;
     if (handler != null) handler(this, ca);
 }
コード例 #38
0
 private void HandleClientDisconnected(DtpNodeSession sender, ClientDisconnectedEventArgs e)
 {
     transportNode.Shutdown();
      sender.Disconnected -= HandleClientDisconnected;
      Completed?.Invoke(this, EventArgs.Empty);
 }
コード例 #39
0
ファイル: Client Management.cs プロジェクト: vercas/vProto
        /* Events from clients...
         */



        void h_Disconnected(BaseClient sender, ClientDisconnectedEventArgs e)
        {
            _RemoveClient(sender);

            OnClientDisconnected(new ServerClientDisconnectedEventArgs(sender, e.Exception));
        }
コード例 #40
0
        private void OnClientDisconnected(object sender, ClientDisconnectedEventArgs e)
        {
            var client = GetClient(e.Channel);
            if (client != null)
                client.Cleanup();

            //TODO: Log if we can't match the client.
        }
コード例 #41
0
ファイル: Events.cs プロジェクト: vercas/vProto
        /// <summary>
        /// Raises the Disconnected event.
        /// </summary>
        /// <param name="e">Desired event arguments.</param>
        protected virtual void OnDisconnected(ClientDisconnectedEventArgs e)
        {
            ClientEventHandler<ClientDisconnectedEventArgs> handler = Disconnected;

            if (handler != null)
            {
                handler(this, e);
            }
        }
コード例 #42
0
ファイル: Server.cs プロジェクト: Zakant/SimpleNetworkCSharp
 /// <summary>
 /// Löst das <see cref="ClientDisconnected"/> Ereignis aus.
 /// </summary>
 /// <param name="c">Der Remotehost, zu dem die Verbindung verloren gegangen ist.</param>
 /// <param name="reason">Der Grund für den Verbindungsabbruch.</param>
 /// <returns>Die verwendeten Ereignis Argumente.</returns>
 protected ClientDisconnectedEventArgs RaiseClientDisconnected(IClient c, DisconnectReason reason)
 {
     var myevent = ClientDisconnected;
     var args = new ClientDisconnectedEventArgs(c, reason);
     if (myevent != null)
         myevent(this, args);
     return args;
 }
コード例 #43
0
 /// <summary>
 /// Fires ClientDisconnectedEvent in the current thread
 /// </summary>
 /// <param name="eventArgs"></param>
 private void OnClientDisconnected(ClientDisconnectedEventArgs eventArgs)
 {
     _synchronizationContext.Post(
         e => ClientDisconnectedEvent.SafeInvoke(this, (ClientDisconnectedEventArgs) e), eventArgs);
 }