private void ClientConnectionCallback(IAsyncResult ar) { Socket listener = default(Socket); Socket handler = default(Socket); SocketsServerClientConnectionHandler newClientConnectionHandler = null; try { this._tcpLsn.Server.BeginAccept(new AsyncCallback(ClientConnectionCallback), this._tcpLsn.Server); } catch (Exception) { } try { listener = (Socket)ar.AsyncState; handler = listener.EndAccept(ar); newClientConnectionHandler = new SocketsServerClientConnectionHandler(handler); } catch (ObjectDisposedException) { //do nothing } catch (Exception ex2) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex2.ToString()); newClientConnectionHandler = null; } if (!(newClientConnectionHandler == null)) { try { this.ClientsConnectionsTable.AddClientSocketHandler(newClientConnectionHandler); } catch (Exception) { } try { if (NewClientConnectionEvent != null) { NewClientConnectionEvent(newClientConnectionHandler); } } catch (Exception) { } try { newClientConnectionHandler.handlerSocket.BeginReceive(newClientConnectionHandler.DataReceptionBuffer, 0, newClientConnectionHandler.DataReceptionBufferSize, (System.Net.Sockets.SocketFlags) 0, new AsyncCallback(ClientDataReceptionCallback), newClientConnectionHandler); } catch (Exception) { } } }
public void BroadCastData(SocketData Data) { lock (this._connectedClientsTable) { IEnumerator enumm = default(IEnumerator); SocketsServerClientConnectionHandler client = default(SocketsServerClientConnectionHandler); enumm = this._connectedClientsTable.GetEnumerator(); if (this._connectedClientsTable.NumOfConnectedClients > 0) { while (enumm.MoveNext()) { client = (SocketsServerClientConnectionHandler)enumm.Current; try { this.SendDataToClient(client, Data); } catch (ObjectDisposedException) { } catch (Exception ex) { string msg = ""; msg = "Error broadcasting data to connected clients : " + ex.ToString(); CustomEventLog.DisplayEvent(EventLogEntryType.Error, msg); } } } } }
internal void STXDSSClientConnectionIdentificationAndConnection(DPE_Client client, string publicationConnectionHandlerID, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { if (client.ClientID != this.publisherSTXDSSClient.ClientID) { //only registers as sbscriptors other client different from the publisher if (this._STXDSS_PublicationClientConnectionsManager.Set_STXDSSClientConnection(client, publicationConnectionHandlerID, connectionMode)) { //------------------------------------------------------------------------------------------ //sends to the client the last update of the publication SocketsServerClientConnectionHandler handler = default(SocketsServerClientConnectionHandler); handler = this._STXDSS_PublicationClientConnectionsManager.GetClientPublicationConnectionHandler(client); if (!(handler == null)) { if (connectionMode == DPE_ServerDefs.DPE_PublicationConnectionMode.ReceiveLastPublicationStatus) { this.SchedulePublicationUpdateOnClientConnection(handler); } } //------------------------------------------------------------------------------------------- try { this.RaiseNewConnectionEvent(client); } catch (Exception) { } } } }
private void ClientConnectionFinishCDB(SocketsServer server, SocketsServerClientConnectionHandler ClientHandler) { this._STXDSS_PublicationClientConnectionsManager.UnlogPendingSocketClientMatchConnectionWithSTXDSSClientTable(ClientHandler); DPE_Client client = default(DPE_Client); client = this._STXDSS_PublicationClientConnectionsManager.GetSubscriptorClient(ClientHandler); if (!(client == null)) { try { this._STXDSS_PublicationClientConnectionsManager.RemoveClientSubscription(ClientHandler); } catch (Exception) { } try { if (SubscriptionDeattachmentEvent != null) { SubscriptionDeattachmentEvent(this, client); } } catch (Exception) { } } }
private void FinishClientSocketConnection(SocketsServerClientConnectionHandler ClientHandler) { try { ClientHandler.CloseConnection(); } catch (Exception) { //do no handling } try { ClientHandler.Dispose(); } catch (Exception) { } try { lock (this.ClientsConnectionsTable) { this.ClientsConnectionsTable.RemoveClientSocketHandler(ClientHandler); } } catch (Exception) { //do no handling } }
public void eventHandling_ClientConnectionFinished(SocketsServer server, SocketsServerClientConnectionHandler ClientHandler) { // a client is disconnected from one of the servers so then is pushed into the stack to make it available //for the next request for a server available wiht room for connections try { if (server.ClientConnectionsCount < this._maxNumberOfClientsPerServer) { if (server.ClientConnectionsCount > 0) { this._serversStack.Push(server); } else { if (this._discardServersWhenThereWerentClientsConnected) { this.DisposeServer(server); } } } } catch (Exception) { } }
private void eventHandling_NewClientConnection(SocketsServerClientConnectionHandler ClientHandler) { try { } catch (Exception) { } }
internal void AddClientSocketHandler(SocketsServerClientConnectionHandler ClientSocketHandler) { if (!this._ClientsSocketHandlerTable.Contains(ClientSocketHandler.ClientID)) { this._ClientsSocketHandlerTable.Add(ClientSocketHandler.ClientID, ClientSocketHandler); } else { throw (new Exception("The client " + ClientSocketHandler.IdentityString + " is already contained in the handling Table")); } }
internal void RemoveClientSocketHandler(SocketsServerClientConnectionHandler ClientSocketHandler) { if (this._ClientsSocketHandlerTable.Contains(ClientSocketHandler.ClientID)) { this._ClientsSocketHandlerTable.Remove(ClientSocketHandler.ClientID); } else { throw (new Exception("The client " + ClientSocketHandler.IdentityString + " is not registered the handling Table")); } }
internal bool LogPendingSocketClientMatchConnectionWithSTXDSSClientTable(SocketsServerClientConnectionHandler ClientHandler) { if (!this._PendingSocketClientMatchWithSTXDSSClientTable.ContainsKey(ClientHandler.ClientID)) { this._PendingSocketClientMatchWithSTXDSSClientTable.Add(ClientHandler.ClientID, ClientHandler); return(true); } else { return(false); } }
private void FinishAllClientSocketConnections() { IEnumerator enumm = default(IEnumerator); SocketsServerClientConnectionHandler client = default(SocketsServerClientConnectionHandler); enumm = this.ClientsConnectionsTable.GetEnumerator(); while (enumm.MoveNext()) { client = (SocketsServerClientConnectionHandler)enumm.Current; this.FinishClientSocketConnection(client); } }
private void ClientConnectionFinished(SocketsServer server, SocketsServerClientConnectionHandler ClientHandler) { try { string msg = DateTime.Now.ToString() + " -> " + ClientHandler.IdentityString; this.SetListBoxItem(this.lstOutgoingConnections, msg); this.RemoveListBoxItem(this.lstConnectedClients, ClientHandler); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
internal DPE_Client GetSubscriptorClient(SocketsServerClientConnectionHandler publicationConnectionHandler) { if (this._socketConnectionHandlerToClientREferenceTable.ContainsKey(publicationConnectionHandler.ClientID)) { DPE_Client client = default(DPE_Client); client = (DPE_Client)this._socketConnectionHandlerToClientREferenceTable[publicationConnectionHandler.ClientID]; return(client); } else { return(null); } }
private void eventHandling_ClientDataReceived(SocketsServer server, SocketsServerClientConnectionHandler ClientHandler, SocketData data) { try { if (DataReceivedFromClientEvent != null) { DataReceivedFromClientEvent(server, ClientHandler, data); } } catch (Exception) { } }
public dynamic Clone() { SocketsServerClientConnectionsHandlerTable newTable = new SocketsServerClientConnectionsHandlerTable(); IEnumerator enumm = default(IEnumerator); SocketsServerClientConnectionHandler client = default(SocketsServerClientConnectionHandler); enumm = this.GetEnumerator(); while (enumm.MoveNext()) { client = (SocketsServerClientConnectionHandler)enumm.Current; newTable.AddClientSocketHandler(client); } return(newTable); }
private void NewClientConnection(SocketsServerClientConnectionHandler ClientHandler) { try { //adds the client to the clients this.SetListBoxItem(this.lstConnectedClients, ClientHandler); string msg = ""; msg = ClientHandler.ConnectionDateTime + " -> " + ClientHandler.IdentityString; this.SetListBoxItem(this.lstIncommingConnections, msg); } catch (Exception) { //MsgBox(ex.Message) } }
internal void SchedulePublicationUpdateOnClientConnection(SocketsServerClientConnectionHandler clientHandler) { try { this._updatePublicationOnClientConnectionQueue.Enqueue(clientHandler); System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(THREAD_FCN_UpdatePublicatonOnSubscriptorConnection)); thread.IsBackground = true; thread.Priority = ThreadPriority.Normal; thread.Start(); } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } }
internal dynamic Set_STXDSSClientConnection(DPE_Client client, string publicationConnectionHandlerID, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { if (this._PendingSocketClientMatchWithSTXDSSClientTable.ContainsKey(publicationConnectionHandlerID)) { SocketsServerClientConnectionHandler socketConnectionHandler = default(SocketsServerClientConnectionHandler); socketConnectionHandler = (SocketsServerClientConnectionHandler)this._PendingSocketClientMatchWithSTXDSSClientTable[publicationConnectionHandlerID]; if (socketConnectionHandler == null) { throw (new Exception("There is not registered a socket connection handler of the client \'" + client.Name + "\' in the publication named \'" + this._publicationOwner.PublicationName + "\'")); } this.RegisterNewSubscriptorToPublication(client, socketConnectionHandler, connectionMode); //regisers in a table the relation of the socket client that belong to the stxdssclient for //further reference if (!this._socketConnectionHandlerToClientREferenceTable.ContainsKey(socketConnectionHandler.ClientID)) { this._socketConnectionHandlerToClientREferenceTable.Add(socketConnectionHandler.ClientID, client); } //regiosters the relation of the socket connection woth the client for further reference if (!this._STXDSSClientTosocketConnectionHandlerReferenceTable.ContainsKey(client.ClientID)) { this._STXDSSClientTosocketConnectionHandlerReferenceTable.Add(client.ClientID, socketConnectionHandler); } //removes from a table the pending match registration this.UnlogPendingSocketClientMatchConnectionWithSTXDSSClientTable(socketConnectionHandler); return(true); } else { //the connection to the publication throuh the socket server don't exists when this happens so then the match is scheduled in a task PublicationConnectionClientMatchRegister matchLog = new PublicationConnectionClientMatchRegister(client, publicationConnectionHandlerID, connectionMode); this._posponedMatchQueue.Enqueue(matchLog); this._posponedMatchTimer.Start(); return(false); } }
public void btnSendData_Click(System.Object sender, System.EventArgs e) { try { if (this.CFDataManagerCointainer1.DataCount <= 0) { throw (new Exception("No data available to send")); } SocketData data = this.CFDataManagerCointainer1.SelectedData; if (!(data == null)) { SocketsServerClientConnectionHandler client = this.GetSelectedClient(); this._DataSocketServer.SendDataToClient(client, data); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private SocketsServerClientConnectionHandler GetSelectedClient() { if (this.lstConnectedClients.Items.Count > 0) { if (this.lstConnectedClients.SelectedIndex >= 0) { SocketsServerClientConnectionHandler client = default(SocketsServerClientConnectionHandler); client = (CommunicationsLibrary.Services.SocketsDataDistribution.ClientConnectionsHandling.SocketsServerClientConnectionHandler) this.lstConnectedClients.SelectedItem; return(client); } else { throw (new Exception("No selected client from list")); } } else { throw (new Exception("No clients available on List")); } }
public void tmrAutomaticSendToSelectedClient_Tick(System.Object sender, System.EventArgs e) { try { SocketsServerClientConnectionHandler clnt = default(SocketsServerClientConnectionHandler); clnt = (CommunicationsLibrary.Services.SocketsDataDistribution.ClientConnectionsHandling.SocketsServerClientConnectionHandler) this.lstConnectedClients.SelectedItem; IEnumerator enumm = default(IEnumerator); enumm = this.lstAutoBroadCast.Items.GetEnumerator(); Data dat = default(Data); SocketData sockdat = default(SocketData); while (enumm.MoveNext()) { dat = (CommunicationsUISupportLibrary.Data)enumm.Current; sockdat = this.GetSocketData(dat); this._DataSocketServer.SendDataToClient(clnt, sockdat); } } catch (Exception) { } }
internal void RemoveClientSubscription(SocketsServerClientConnectionHandler publicationConnectionHandler) { DPE_Client client = default(DPE_Client); client = this.GetSubscriptorClient(publicationConnectionHandler); if (!(client == null)) { this.UnregisterSubscriptorFromPublication(client); } if (this._STXDSSClientTosocketConnectionHandlerReferenceTable.ContainsKey(client.ClientID)) { this._STXDSSClientTosocketConnectionHandlerReferenceTable.Remove(client.ClientID); } if (this._socketConnectionHandlerToClientREferenceTable.ContainsKey(publicationConnectionHandler.ClientID)) { this._socketConnectionHandlerToClientREferenceTable.Remove(publicationConnectionHandler.ClientID); } this.UnlogPendingSocketClientMatchConnectionWithSTXDSSClientTable(publicationConnectionHandler); }
private void ClientDataReceived(SocketsServer server, SocketsServerClientConnectionHandler ClientHandler, SocketData data) { try { this._dataReceptionCount++; this.SetTextBoxText(this.txtDataReceivedCount, System.Convert.ToString(this._dataReceptionCount)); this.ListBox_Items_Clear(this.lstDataAttributes); if (this.chkPutIncommingDataIntoList.Checked) { string msg = "[FROM=" + ClientHandler.IdentityString + "]->[DATA LENGTH = " + System.Convert.ToString(data.DataLenght) + "][DATANAME= " + data.DataName + "][DATA = " + data.XMLDataString + "]"; this.SetListBoxItem(this.lstBoxDataReceived, data); } if (this.chkBroadCastReceivedData.Checked) { server.BroadCastData(data); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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 { } }
private void RegisterNewSubscriptorToPublication(DPE_Client subscriptorClient, SocketsServerClientConnectionHandler connectionHandler, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode) { try { DataRow clientRow = this._STXDSSClienstSubscribedRegistryTable.NewRow(); clientRow["Client Name"] = subscriptorClient.Name; clientRow["Client ID"] = subscriptorClient.ClientID; clientRow["Client HostName"] = subscriptorClient.HostName; clientRow["Client AppDomain"] = subscriptorClient.ApplicationDomainName; clientRow["Connection Date Time"] = System.Convert.ToString(DateTime.Now); clientRow["Client Network ID"] = System.Convert.ToString(connectionHandler.ClientID); string cnnmode = ""; switch (connectionMode) { case DPE_ServerDefs.DPE_PublicationConnectionMode.NotReceiveLastPublicationStatus: cnnmode = "Not Receive Last Status"; break; case DPE_ServerDefs.DPE_PublicationConnectionMode.ReceiveLastPublicationStatus: cnnmode = "Receive Last Status"; break; default: cnnmode = "Undefined Status"; break; } clientRow["Connection Mode"] = cnnmode; lock (this._STXDSSClienstSubscribedRegistryTable) { this._STXDSSClienstSubscribedRegistryTable.Rows.Add(clientRow); } CustomEventLog.DisplayEvent(EventLogEntryType.Information, "Client \'" + subscriptorClient.Name + "\' connected to publication \'" + this._publicationOwner.PublicationName + "\'"); } catch (Exception) { } }
private void _posponedMatchTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { try { this._posponedMatchTimer.Stop(); PublicationConnectionClientMatchRegister matchLog = null; lock (this._posponedMatchQueue) { matchLog = (PublicationConnectionClientMatchRegister)this._posponedMatchQueue.Dequeue(); } if (!(matchLog == null)) { if (matchLog.GetElapsedSeconds() < MAX_MATCH_INTERVAL_LAP_IN_SECONDS) { //realizes the matching if (this._PendingSocketClientMatchWithSTXDSSClientTable.ContainsKey(matchLog.PublicationConnectionHandlerID)) { SocketsServerClientConnectionHandler socketConnectionHandler = default(SocketsServerClientConnectionHandler); socketConnectionHandler = (SocketsServerClientConnectionHandler)this._PendingSocketClientMatchWithSTXDSSClientTable[matchLog.PublicationConnectionHandlerID]; if (socketConnectionHandler == null) { throw (new Exception("There is not registered a socket connection handler of the client \'" + matchLog.Client.Name + "\' in the publication named \'" + this._publicationOwner.PublicationName + "\'")); } this.RegisterNewSubscriptorToPublication(matchLog.Client, socketConnectionHandler, matchLog.ConnectionMode); //regisers in a table the relation of the socket client that belong to the stxdssclient for //further reference if (!this._socketConnectionHandlerToClientREferenceTable.ContainsKey(socketConnectionHandler.ClientID)) { this._socketConnectionHandlerToClientREferenceTable.Add(socketConnectionHandler.ClientID, matchLog.Client); } //regiosters the relation of the socket connection woth the client for further reference if (!this._STXDSSClientTosocketConnectionHandlerReferenceTable.ContainsKey(matchLog.Client.ClientID)) { this._STXDSSClientTosocketConnectionHandlerReferenceTable.Add(matchLog.Client.ClientID, socketConnectionHandler); } this.UnlogPendingSocketClientMatchConnectionWithSTXDSSClientTable(socketConnectionHandler); //------------------------------------------------------------------------------------------ //sends to the client the last update of the publication SocketsServerClientConnectionHandler handler = default(SocketsServerClientConnectionHandler); handler = this.GetClientPublicationConnectionHandler(matchLog.Client); if (!(handler == null)) { if (matchLog.ConnectionMode == DPE_ServerDefs.DPE_PublicationConnectionMode.ReceiveLastPublicationStatus) { this._publicationOwner.SchedulePublicationUpdateOnClientConnection(handler); } } //------------------------------------------------------------------------------------------- try { this._publicationOwner.RaiseNewConnectionEvent(matchLog.Client); } catch (Exception) { } } else { if (matchLog.GetElapsedSeconds() < MAX_MATCH_INTERVAL_LAP_IN_SECONDS) { lock (this._posponedMatchQueue) { this._posponedMatchQueue.Enqueue(matchLog); } } } } } } catch (Exception ex) { CustomEventLog.WriteEntry(ex); } finally { if (this._posponedMatchQueue.Count > 0) { this._posponedMatchTimer.Start(); } } }
private void NewIncommingConnectionCDB(SocketsServerClientConnectionHandler ClientHandler) { this._STXDSS_PublicationClientConnectionsManager.LogPendingSocketClientMatchConnectionWithSTXDSSClientTable(ClientHandler); }
private void THREAD_FCN_UpdatePublicatonOnSubscriptorConnection() { try { SocketsServerClientConnectionHandler ClientHandler = default(SocketsServerClientConnectionHandler); if (this._updatePublicationOnClientConnectionQueue.Count > 0) { ClientHandler = null; try { ClientHandler = (SocketsServerClientConnectionHandler)this._updatePublicationOnClientConnectionQueue.Dequeue(); } catch (Exception) { ClientHandler = null; } if (!(ClientHandler == null)) { lock (this._variablesPublishedRegistry) { IEnumerator enumm = default(IEnumerator); string variableName = ""; DPE_PublicationData lastDataValue = default(DPE_PublicationData); enumm = this._variablesPublishedRegistry.PublishedVariablesNamesList.GetEnumerator(); while (enumm.MoveNext()) { try { variableName = System.Convert.ToString(enumm.Current); lastDataValue = this._variablesPublishedRegistry.GetLastRecordedDataValue(variableName); if (!(lastDataValue == null)) { SocketData ds = default(SocketData); ds = this.ConvertPublicationDataToSocketDataType(lastDataValue); try { //Uses the sockets server to send data exclusively to a client this._publicationSocketsServer.SendDataToClient(ClientHandler, ds); } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } } } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } } } } } } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } }
private void ClientDataReceptionCallback(IAsyncResult ar) { //process the data incopmming from the client SocketsServerClientConnectionHandler clientCnnHandler = default(SocketsServerClientConnectionHandler); clientCnnHandler = (SocketsServerClientConnectionHandler)ar.AsyncState; try { int bytesRead = clientCnnHandler.handlerSocket.EndReceive(ar); if (bytesRead > 0) { try { this._incommingDataProcessingQueue.Enqueue(clientCnnHandler); } catch (Exception) { } //prepares to receive data again try { clientCnnHandler.handlerSocket.BeginReceive(clientCnnHandler.DataReceptionBuffer, 0, clientCnnHandler.DataReceptionBufferSize, (System.Net.Sockets.SocketFlags) 0, new AsyncCallback(ClientDataReceptionCallback), clientCnnHandler); } catch (Exception) { } } else { try { this.FinishClientSocketConnection(clientCnnHandler); } catch (Exception) { } try { if (ClientConnectionFinishedEvent != null) { ClientConnectionFinishedEvent(this, clientCnnHandler); } } catch (Exception) { } } } catch (ObjectDisposedException) { //do nothing 'the connection already finished } catch (SocketException) { try { this.FinishClientSocketConnection(clientCnnHandler); } catch (Exception) { } try { if (ClientConnectionFinishedEvent != null) { ClientConnectionFinishedEvent(this, clientCnnHandler); } } catch (Exception) { } } catch (Exception ex) { CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString()); } }
public void SendDataToClient(SocketsServerClientConnectionHandler ClientHandler, SocketData Data) { ClientHandler.SendData(Data); }