private void AfterConnect(Task task) { if (task.IsCompleted) { if (_ClientWs.State == WebSocketState.Open) { Task.Run(() => { _Connected = true; Task.Run(() => DataReceiver(), _Token); ServerConnected?.Invoke(this, EventArgs.Empty); }, _Token); } else { _Connected = false; ServerDisconnected?.Invoke(this, EventArgs.Empty); } } else { _Connected = false; ServerDisconnected?.Invoke(this, EventArgs.Empty); } }
private void AfterConnect(Task task) { if (task.IsCompleted) { if (_ClientWs.State == WebSocketState.Open) { Task.Run(() => { Task.Run(() => DataReceiver(), _Token); ServerConnected?.Invoke(this, EventArgs.Empty); }, _Token); } else { if (DisconnectEventConnecting) { ServerDisconnected?.Invoke(this, EventArgs.Empty); InternalServerDisconnected?.Invoke(this, EventArgs.Empty); } } } else { if (DisconnectEventConnecting) { ServerDisconnected?.Invoke(this, EventArgs.Empty); InternalServerDisconnected?.Invoke(this, EventArgs.Empty); } } }
private void OnConnect(Server server) { Log("Connected to " + Host + ":" + Port); client.Mutex.WaitOne(); ServerConnected?.Invoke(server); server.SendMessage("{ 'getProperties': { 'version': 512 } }"); client.Mutex.ReleaseMutex(); }
private void ConnAcceptedEvent(Socket client) { SocketClientEventArgs args = new SocketClientEventArgs(); args.socket = client; ServerConnected?.Invoke(this, args); ListeningForServerMessage(client); }
private void Connect() { if (IntegratedSecurity || !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password)) { try { ServerConnected?.Invoke(this, GetDatabaseList(false)); } catch { MessageBox.Show("Invalid login."); } } }
/// <summary> /// Asynchronouses the listener. /// </summary> /// <param name="ar">The ar.</param> /// <exception cref="NetProxyException">There was a problem connecting to the server.</exception> private void AsyncListener(IAsyncResult ar) { try { listen = (TcpListener)ar.AsyncState; client = listen.EndAcceptTcpClient(ar); client.GetStream().BeginRead(clientBuffer, 0, clientBuffer.Length, new AsyncCallback(GetClientData), client); ClientConnected?.Invoke(); // listen.Stop(); LightBringer.GetStream().BeginRead(serverBuffer, 0, serverBuffer.Length, new AsyncCallback(GetServerData), LightBringer); ServerConnected?.Invoke(); } catch (Exception e) { SendError(e, this); } }
/// <summary> /// Connects the specified ip. /// </summary> /// <param name="ip">The ip.</param> /// <param name="port">The port.</param> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns> public virtual bool Connect(string ip = null, int port = 0) { Port = port; IpAddress = ip; if (string.IsNullOrEmpty(ip)) { IpAddress = Globals.IP; } if (port == 0) { Port = Globals.Port; } var ok = CreateSender(IpAddress, Port); if (!ok) { if (Globals.Debug) { Console.WriteLine(Resources.Failed_to_connect_to + " " + IpAddress + " , " + Resources.port_number + " = " + Port); } return(false); } fListenThread = new Thread(ListenForData); fListenThread.Start(); if (Globals.Debug) { Console.WriteLine(Resources.Connected_to + " " + IpAddress + " , " + Resources.port_number + " = " + Port); } if (ServerConnected != null) { ServerConnected.Invoke(); } return(true); }
protected override void ProcessMessage(IpcMessage message) { if (message is NetIpcLogMessage logMsg) { HandleLogMessage(logMsg); } else if (message.MessageType == IpcMessageType.NetIpcClientDisconnected) { ServerDisconnected?.Invoke(this, null); } else if (message.MessageType == IpcMessageType.NetIpcClientConnected) { ServerConnected?.Invoke(this, null); } else if (message is NetIpcAutoReconnectResponseMessage autoMsg) { HandleAutoReconnectStateMessage(autoMsg); } }
public void Host(int port = 5000) { Console.WriteLine("Server Ready!"); NetworkedMultiplayerENet peer = new(); Error error = peer.CreateServer(port); if (error != Error.Ok) { GD.PushError(error.ToString()); } NetworkPeer = peer; Console.WriteLine(NetworkPeer.GetConnectionStatus()); if (NetworkPeer.GetConnectionStatus() == NetworkedMultiplayerPeer.ConnectionStatus.Connected) { Console.WriteLine("Server Is Live"); ServerConnected?.Invoke(this, new ServerConnected()); } }
private void ConnectCallback(IAsyncResult ar) { try { // Retrieve the socket from the state object. Socket client = (Socket)ar.AsyncState; // Complete the connection. client.EndConnect(ar); //Signal Connection complete ServerConnected?.Invoke(); // Begin receiving the data from the remote device. client.BeginReceive(player.buffer, 0, ClientPlayer.BufferSize, 0, new AsyncCallback(ReadCallback), player); } catch (Exception e) { Logger.Debug(e.ToString()); ServerFailedToConnect?.Invoke(); } }
private void MeshClientServerConnected(object sender, EventArgs args) { Logger?.Invoke("[MeshClient] Server " + PeerNode.IpPort + " connected"); ServerConnected?.Invoke(this, new ServerConnectionEventArgs(PeerNode)); }
protected virtual void OnServerConnected() { ServerConnected?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Raises the event <see cref="ServerConnected"/>. /// </summary> protected internal void RaiseServerConnected() { _log.Debug(nameof(RaiseServerConnected)); ServerConnected?.Invoke(this, EventArgs.Empty); }
internal void HandleServerConnected(object sender, ConnectionEventArgs args) { WrappedEventHandler(() => ServerConnected?.Invoke(sender, args), "ServerConnected", sender); }
internal void HandleServerConnected(object sender, EventArgs args) { ServerConnected?.Invoke(sender, args); }
/// <summary> /// Start the client and establish a connection to the server. /// </summary> /// <returns></returns> public Task StartAsync() { _Client = new TcpClient(); _Stats = new Statistics(); IAsyncResult asyncResult = null; WaitHandle waitHandle = null; bool connectSuccess = false; if (_Mode == Mode.Tcp) { #region TCP Logger?.Invoke("[WatsonTcpClient] Connecting to " + _ServerIp + ":" + _ServerPort); _Client.LingerState = new LingerOption(true, 0); asyncResult = _Client.BeginConnect(_ServerIp, _ServerPort, null, null); waitHandle = asyncResult.AsyncWaitHandle; try { connectSuccess = waitHandle.WaitOne(TimeSpan.FromSeconds(_ConnectTimeoutSeconds), false); if (!connectSuccess) { _Client.Close(); throw new TimeoutException("Timeout connecting to " + _ServerIp + ":" + _ServerPort); } _Client.EndConnect(asyncResult); _SourceIp = ((IPEndPoint)_Client.Client.LocalEndPoint).Address.ToString(); _SourcePort = ((IPEndPoint)_Client.Client.LocalEndPoint).Port; _TcpStream = _Client.GetStream(); _SslStream = null; Connected = true; } catch (Exception) { throw; } finally { waitHandle.Close(); } #endregion TCP } else if (_Mode == Mode.Ssl) { #region SSL Logger?.Invoke("[WatsonTcpClient] Connecting with SSL to " + _ServerIp + ":" + _ServerPort); _Client.LingerState = new LingerOption(true, 0); asyncResult = _Client.BeginConnect(_ServerIp, _ServerPort, null, null); waitHandle = asyncResult.AsyncWaitHandle; try { connectSuccess = waitHandle.WaitOne(TimeSpan.FromSeconds(_ConnectTimeoutSeconds), false); if (!connectSuccess) { _Client.Close(); throw new TimeoutException("Timeout connecting to " + _ServerIp + ":" + _ServerPort); } _Client.EndConnect(asyncResult); _SourceIp = ((IPEndPoint)_Client.Client.LocalEndPoint).Address.ToString(); _SourcePort = ((IPEndPoint)_Client.Client.LocalEndPoint).Port; if (AcceptInvalidCertificates) { // accept invalid certs _SslStream = new SslStream(_Client.GetStream(), false, new RemoteCertificateValidationCallback(AcceptCertificate)); } else { // do not accept invalid SSL certificates _SslStream = new SslStream(_Client.GetStream(), false); } _SslStream.AuthenticateAsClient(_ServerIp, _SslCertificateCollection, SslProtocols.Tls12, !AcceptInvalidCertificates); if (!_SslStream.IsEncrypted) { throw new AuthenticationException("Stream is not encrypted"); } if (!_SslStream.IsAuthenticated) { throw new AuthenticationException("Stream is not authenticated"); } if (MutuallyAuthenticate && !_SslStream.IsMutuallyAuthenticated) { throw new AuthenticationException("Mutual authentication failed"); } Connected = true; } catch (Exception) { throw; } finally { waitHandle.Close(); } #endregion SSL } else { throw new ArgumentException("Unknown mode: " + _Mode.ToString()); } ServerConnected?.Invoke(this, EventArgs.Empty); return(DataReceiver()); }
private void RaiseServerConnected() { ServerConnected?.Invoke(this, new TcpServerConnectedEventArgs(RemoteEndPoint, LocalEndPoint)); }
public void OnServerConnected() { IsConnected = true; ServerConnected?.Invoke(); StartHeartBeat(); }
/// <summary> /// 连接成功触发方法 /// </summary> /// <param name="ipAddresses"></param> /// <param name="port"></param> private void RaiseServerConnected(IPAddress[] ipAddresses, int port) { ServerConnected?.Invoke(this, new TcpServerConnectedEventArgs(ipAddresses, port)); }
internal void HandleServerConnected(object sender, EventArgs args) { CatchAndReport(() => ServerConnected?.Invoke(sender, args), "ServerConnected", sender); }
internal void HandleAuthenticationSucceeded(object sender, EventArgs args) { WrappedEventHandler(() => ServerConnected?.Invoke(sender, args), "ServerConnected", sender); }
internal virtual void OnServerConnected(EventArgs e) => ServerConnected?.Invoke(this, e);
private void OnSererConnected() { ServerConnected?.Invoke(); }
protected virtual void OnServerConnected() { ServerConnected?.Invoke(this, new EventArgs()); }
/// <summary> /// Trigger ServerConnected Event /// </summary> /// <param name="ipAddress"></param> /// <param name="port"></param> protected virtual void OnServerConnected(IPAddress[] ipAddress, int port) { ServerConnected?.Invoke(this, new TCPServerConnectedEventArgs(ipAddress[0], port)); }