private void ConsumeData(ChannelData <byte[]> channelData) { if (channelData != null && _channelDataReceivedAction != null) { _channelDataReceivedAction(channelData); } }
private ChannelData <byte[]> ProduceData() { ChannelData <byte[]> channelData = null; int receivedBytesCount = 0; try { receivedBytesCount = _socket.ReceiveFrom(_buffer, ref _remoteEndPoint); } catch { } if (receivedBytesCount > 0) { try { byte[] receivedBytes = new byte[receivedBytesCount]; Buffer.BlockCopy(_buffer, 0, receivedBytes, 0, receivedBytesCount); IPEndPoint currentEndPoint = new IPEndPoint(((IPEndPoint)_remoteEndPoint).Address, ((IPEndPoint)_remoteEndPoint).Port); channelData = new ChannelData <byte[]>(receivedBytes, currentEndPoint, DateTime.Now); } catch (Exception ex) { _logWriter.Log("UdpChannel ProduceData exception", ex); } } return(channelData); }
private void NotifyRawDataReceived(byte[] rawData) { if (_channelDataReceivedAction != null) { ChannelData <byte[]> channelData = new ChannelData <byte[]>(rawData, _remoteIPEndPoint, DateTime.Now); _channelDataReceivedAction(channelData); } }
public void RawDataReceived(TcpConnectionInfo connection, byte[] data) { if (_channelDataReceivedAction != null) { ChannelData <byte[]> channelData = new ChannelData <byte[]>(data, connection.RemoteEndPoint, DateTime.Now); _channelDataReceivedAction(channelData); } }
private void ConnectToHost() { string url = _requestUrl; string address = _ipHost + ":" + _port; while (!_stopRequest) { try { string responseLine = null; HttpWebResponse response = null; while (response == null && !_stopRequest) { WebRequest request = WebRequest.Create(url); request.ContentType = "text/plain"; request.Timeout = 10 * 1000; // 10 seconds in milliseconds response = (HttpWebResponse)request.GetResponse(); if (response != null) { Task.Factory.StartNew(() => OnConnected(_hostIPEndpoint)); using (Stream dataStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(dataStream, _currentEncoding)) { reader.BaseStream.ReadTimeout = 10 * 1000; while (!reader.EndOfStream && !_stopRequest) { responseLine = reader.ReadLine(); if (responseLine != "" && _channelDataReceivedAction != null) { ChannelData <string> channelData = new ChannelData <string>(responseLine, _hostIPEndpoint, DateTime.Now); _channelDataReceivedAction(channelData); } } } } response = null; } Thread.Sleep(_requestIntervalInMS); } } catch (Exception ex) { OnDisconnected(_hostIPEndpoint, ex.Message); _logWriter.Log("HttpReaderChannel ConnectToHost function exception", ex); Thread.Sleep(_exceptionIntervalInMS); } } Task.Factory.StartNew(() => OnDisconnected(_hostIPEndpoint, string.Empty)); }
public override void SendData(ChannelData <byte[]> channelData) { try { if (_ns != null && _ns.CanWrite) { _ns.Write(channelData.RawData, 0, channelData.RawData.Length); } } catch (Exception ex) { _logWriter.Log("TcpClient SendData function exception", ex); } }
public override void SendData(ChannelData <string> channelData) { }
public override void SendData(ChannelData <byte[]> channelData) { _TcpListener.Send(channelData.RemoteEndPoint, channelData.RawData); }
public abstract void SendData(ChannelData <T> channelData);
public override void SendData(ChannelData <byte[]> channelData) { _socket.SendTo(channelData.RawData, channelData.RawData.Length, SocketFlags.None, channelData.RemoteEndPoint); }