//Used for service methods. Do not alter method signature public bool Start() { //log.InfoFormat("start"); server = new Server(); rfidReader = new RFIDReader(); log.InfoFormat("Service has started"); server.Listen(IPADDRESS, PORT); server.AcceptTcpClientAsync(); log.InfoFormat("client accepted"); while (!rfidReader.impinjReader.IsConnected) { try { rfidReader.Start(); rfidReader.impinjReader.TagsReported += OnTagsReported; rfidReader.impinjReader.ConnectionLost += OnConnectionLost; log.InfoFormat("Reader started"); } catch (OctaneSdkException ose) { log.Info(ose.Message); } Thread.Sleep(3000); } return(true); }
/*public async Task<FlareTcpClient> AcceptClientAsync(CancellationToken cancellationToken = default) { * EnsureRunning(); * var client = await Server.AcceptTcpClientAsync(cancellationToken).ConfigureAwait(false); * return new FlareTcpClient(client); * }*/ public async Task <FlareTcpClient> AcceptClientAsync() { EnsureRunning(); var client = await Server.AcceptTcpClientAsync().ConfigureAwait(false); return(WrapIntoClient(client)); }
public async Task <string> RecieveAsync(CancellationToken cancellationToken) { TcpClient tcpc = default(TcpClient); tcpc = await Server.AcceptTcpClientAsync(); byte[] recievedBuffer = new byte[1024]; NetworkStream stream = tcpc.GetStream(); await stream.ReadAsync(recievedBuffer, 0, recievedBuffer.Length); string msg = Encoding.ASCII.GetString(recievedBuffer); return(msg); }
private async void Listen() { TcpClient client; try { client = await Server.AcceptTcpClientAsync(); } catch { return; } Listen(); Work(client); }
private async Task ListenAsync(CancellationToken token) { while (!token.IsCancellationRequested) { try { var client = new Client(await Server.AcceptTcpClientAsync()); Clients.Add(client); ReadAsync(client, token); } catch (Exception ex) when(ex is ObjectDisposedException || ex is SocketException) { // This happens when the server is stopped Console.WriteLine("Server stopped."); } } }
public async Task Open() { try { Trace.WriteLine("Starting TCP server"); Server.Start(); //Start listening for connection requests Trace.WriteLine("Starting to listen for Connections"); ClientConnection = await Server.AcceptTcpClientAsync().ConfigureAwait(false); ConnectionStream = ClientConnection.GetStream(); Trace.WriteLine("Connected"); } catch (SocketException e) { Trace.WriteLine($"SocketException: {e}"); Close(); } }
/// <summary> /// Loops clients acceptation while <see cref="Running"/> is set to true. /// </summary> protected async Task AcceptClientsLoopAsync() { while (Running) { TcpClient client = await Server.AcceptTcpClientAsync(); if (Running) { lock (ClientsLocker) { OnClientConnect?.Invoke(client); Clients.Add(client); } } else { client.Close(); client.Dispose(); } } }
public async Task Open() { try { Trace.WriteLine("Starting to listen for Connections"); ClientConnection = await Server.AcceptTcpClientAsync().ConfigureAwait(false); ClientConnection.LingerState.Enabled = false; ClientConnection.LingerState.LingerTime = 0; ClientConnection.ReceiveTimeout = TimeOut; ConnectionStream = ClientConnection.GetStream(); ConnectionStream.ReadTimeout = TimeOut; ConnectionStream.WriteTimeout = TimeOut; Trace.WriteLine("Connected"); } catch (SocketException e) { Trace.WriteLine($"SocketException: {e}"); Close(); } }
public async Task <JfpClient> AcceptJfpClientAsync() { return(new JfpClient(Decorator((await Server.AcceptTcpClientAsync()).GetStream()))); }