private void EventHandling_incommingDataPRocessingTimer_NewItemReceived(object item) { try { byte[] data = (byte[])item; if (!(data == null)) { Services.SocketsDataDistribution.Data.SocketDataContainer container = Services.SocketsDataDistribution.Data.SocketDataContainer.Deserialize(data); SocketData sd = default(SocketData); IEnumerator enumm = container.GetEnumerator(); while (enumm.MoveNext()) { sd = (SocketData)enumm.Current; try { if (DataReceivedEvent != null) { DataReceivedEvent(sd, this); } } catch (Exception) { } } } } catch (Exception) { } }
public SocketsServerClientConnectionHandler(Socket handlerSocket) { this._handlerSocket = handlerSocket; this._handlerSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, SocketsServerDefinitions.MAX_SOCKET_DATA_BUFFER_SIZE); this._handlerSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, SocketsServerDefinitions.MAX_SOCKET_DATA_BUFFER_SIZE); try { IPAddress ipAdd = default(IPAddress); ipAdd = IPAddress.Parse(System.Convert.ToString(((IPEndPoint)_handlerSocket.RemoteEndPoint).Address.ToString())); this._remoteIPAddress = ipAdd.ToString(); IPHostEntry hostIp = default(IPHostEntry); hostIp = Dns.GetHostEntry(ipAdd); this._remoteHostName = hostIp.HostName; } catch (Exception) { this._remoteHostName = "Unknown"; } try { IPEndPoint ip = default(IPEndPoint); ip = (IPEndPoint)this._handlerSocket.RemoteEndPoint; this._remotePortNumber = ip.Port; } catch (Exception) { this._remotePortNumber = -1; } this._localStringID = Guid.NewGuid().ToString("N"); IPEndPoint IPEp = (IPEndPoint)handlerSocket.RemoteEndPoint; this._IPID = new IPEndPoint(IPEp.Address, this._remotePortNumber); this._ClientID = this._IPID.ToString(); try { this._ClientIdentityString = "[CLIENT ID= " + this._localStringID + "] [HOST=" + this._remoteHostName + "] [IP=" + this._remoteIPAddress + "] [PORT=" + System.Convert.ToString(this.RemotePort) + "]"; } catch (Exception) { this._ClientIdentityString = "UNKNOWN"; } this._connectionDateTime = DateTime.Now; this._dataContainer = new Services.SocketsDataDistribution.Data.SocketDataContainer(); this._dataSendTimer = new System.Timers.Timer(250); this._dataSendTimer.Elapsed += this.EventHandling_dataSendTimer_Elapsed; this._dataSendTimer.AutoReset = false; this._dataSendTimer.Stop(); }
public SocketsServerClient(string clientName, string ServerHostName, int ServerListeningPort) { this._serverHostName = ServerHostName; this._serverListeningPortNumber = System.Convert.ToString(ServerListeningPort); this._clientName = clientName.ToUpper(); this._incommingDataPRocessingQueue = new TimedProducerConsumerQueue(); this._incommingDataPRocessingQueue.NewItemDetected += this.EventHandling_incommingDataPRocessingTimer_NewItemReceived; this._dataContainer = new Services.SocketsDataDistribution.Data.SocketDataContainer(); this._outgoingDataTimer = new System.Timers.Timer(150); this._outgoingDataTimer.Elapsed += this.EventHandling_outgoingDataTimer_Elapsed; this._outgoingDataTimer.AutoReset = false; }
private void EventHandling_incommingDataProcessingQueue_NewItemDetected(object item) { try { SocketsServerClientConnectionHandler clientCnnHandler = (SocketsServerClientConnectionHandler)item; if (!(clientCnnHandler == null)) { Services.SocketsDataDistribution.Data.SocketDataContainer container = Services.SocketsDataDistribution.Data.SocketDataContainer.Deserialize(clientCnnHandler.DataReceptionBuffer); IEnumerator enumm = container.GetEnumerator(); SocketsServerClientConnectionHandler client = this._connectedClientsTable.GetClientConnectionHandler(clientCnnHandler.ClientID); SocketData data = default(SocketData); while (enumm.MoveNext()) { data = (SocketData)enumm.Current; try { if (ClientDataReceivedEvent != null) { ClientDataReceivedEvent(this, client, data); } } catch (Exception) { } } } } catch (Exception ex) { CustomEventLog.WriteEntry(ex); } finally { } }