public override bool SetEndpoint( SensorEndpoint endpoint = null ) { //we don't need any endpoints for this Data Intake if( endpoint == null ) return true; return false; }
public override bool SetEndpoint(SensorEndpoint endpoint = null) { //we don't need any endpoints for this Data Intake if (endpoint == null) { return(true); } return(false); }
public void Start( SensorEndpoint endpoint, int messagesToSend ) { _messagesToSend = messagesToSend; _endpoint = endpoint; _doWorkSwitch = true; var sh = new SafeAction<int>( e => RunSocketAsClient( e ), _logger ); TaskWrapper.Run( ( ) => sh.SafeInvoke( CONNECTION_RETRIES ) ); }
public void Start(SensorEndpoint endpoint, int messagesToSend) { _messagesToSend = messagesToSend; _endpoint = endpoint; _doWorkSwitch = true; var sh = new SafeAction <int>(e => RunSocketAsClient(e), _logger); TaskWrapper.Run(() => sh.SafeInvoke(CONNECTION_RETRIES)); }
public override bool SetEndpoint(SensorEndpoint endpoint = null) { if (endpoint == null) { //we need to know endpoint return(false); } _endpoint = endpoint; return(true); }
public override bool SetEndpoint( SensorEndpoint endpoint = null ) { if( endpoint == null ) { //we need to know endpoint return false; } _endpoint = endpoint; return true; }
public void RunSocketServer(SensorEndpoint endpoint) { IPAddress ipAddress; if (!IPAddress.TryParse(endpoint.Host, out ipAddress)) { return; } TcpListener serverSocket = new TcpListener(ipAddress, endpoint.Port); serverSocket.Start( ); TcpClient clientSocket = serverSocket.AcceptTcpClient( ); try { for ( ; ;) { NetworkStream networkStream = clientSocket.GetStream( ); //byte[] bytesFrom = new byte[10025]; //networkStream.Read(bytesFrom, 0, clientSocket.ReceiveBufferSize); //string dataFromClient = Encoding.ASCII.GetString(bytesFrom); //dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$")); SensorDataContract sensorData = RandomSensorDataGenerator.Generate( ); string serializedData = JsonConvert.SerializeObject(sensorData); Byte[] sendBytes = Encoding.ASCII.GetBytes("<" + serializedData + ">"); networkStream.Write(sendBytes, 0, sendBytes.Length); networkStream.Flush( ); Thread.Sleep(SLEEP_TIME_MS); } } catch (Exception ex) { _logger.LogError(ex.ToString( )); } try { serverSocket.Stop( ); } catch (Exception ex) { _logger.LogError(ex.ToString( )); } }
static void Main(string[] args) { ConsoleLogger logger = new ConsoleLogger( ); SocketServiceTestDevice device = new SocketServiceTestDevice(logger); SensorEndpoint endpoint = new SensorEndpoint { Host = "127.0.0.1", Port = 5000 }; device.RunSocketServer(endpoint); }
public void RunSocketServer( SensorEndpoint endpoint ) { IPAddress ipAddress; if( !IPAddress.TryParse( endpoint.Host, out ipAddress ) ) return; TcpListener serverSocket = new TcpListener( ipAddress, endpoint.Port ); serverSocket.Start( ); TcpClient clientSocket = serverSocket.AcceptTcpClient( ); try { for( ; ; ) { NetworkStream networkStream = clientSocket.GetStream( ); //byte[] bytesFrom = new byte[10025]; //networkStream.Read(bytesFrom, 0, clientSocket.ReceiveBufferSize); //string dataFromClient = Encoding.ASCII.GetString(bytesFrom); //dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$")); SensorDataContract sensorData = RandomSensorDataGenerator.Generate( ); string serializedData = JsonConvert.SerializeObject( sensorData ); Byte[] sendBytes = Encoding.ASCII.GetBytes( "<" + serializedData + ">" ); networkStream.Write( sendBytes, 0, sendBytes.Length ); networkStream.Flush( ); Thread.Sleep( SLEEP_TIME_MS ); } } catch( Exception ex ) { _logger.LogError( ex.ToString( ) ); } try { serverSocket.Stop( ); } catch( Exception ex ) { _logger.LogError( ex.ToString( ) ); } }
public void TestRecieveMessagesFromSocketDevice( ) { const int MESSAGES_TO_SEND_BY_SOCKET = 5; try { IList <string> sources = Loader.GetSources( ) .Where(m => m.Contains("Socket")).ToList( ); IList <SensorEndpoint> endpoints = Loader.GetEndpoints( ) .Where(m => m.Name.Contains("Socket")).ToList( ); if (endpoints.Count == 0) { throw new Exception("Need to specify local ip host for Socket interations " + "and name of endpoint should contain \"Socket\""); } GatewayService service = PrepareGatewayService( ); SensorEndpoint endpoint = endpoints.First( ); SocketClientTestDevice device = new SocketClientTestDevice(_logger); device.Start(endpoint, MESSAGES_TO_SEND_BY_SOCKET); DeviceAdapterLoader dataIntakeLoader = new DeviceAdapterLoader( sources, endpoints, _logger); _totalMessagesToSend += MESSAGES_TO_SEND_BY_SOCKET; dataIntakeLoader.StartAll(service.Enqueue, DataArrived); _completed.WaitOne( ); dataIntakeLoader.StopAll( ); _batchSenderThread.Stop(STOP_TIMEOUT_MS); } catch (Exception ex) { _logger.LogError("exception caught: " + ex.StackTrace); } finally { _batchSenderThread.Stop(STOP_TIMEOUT_MS); _sender.Close( ); } }
public void Start( SensorEndpoint endpoint ) { var sh = new SafeAction<SensorEndpoint>( e => RunSocketServer( e ), _logger ); TaskWrapper.Run( ( ) => sh.SafeInvoke( endpoint ) ); }
public abstract bool SetEndpoint( SensorEndpoint endpoint = null );
public void Start(SensorEndpoint endpoint) { var sh = new SafeAction <SensorEndpoint>(e => RunSocketServer(e), _logger); TaskWrapper.Run(() => sh.SafeInvoke(endpoint)); }