コード例 #1
0
        private void HandleTextFromClient(string readTextFromClient, TcpClient clientThatConnected)
        {
            if (readTextFromClient != Common.UnicodeIdentifierCharacter)
            {
                CommunicationMessage receivedCommunicationMessage = new CommunicationMessage(readTextFromClient, Common.CommunicationEventType.TextReceived);

                if (receivedCommunicationMessage.MessageType == (int)Common.CommunicationMessageType.Login)
                {
                    AddAuthenticatedClient(receivedCommunicationMessage, clientThatConnected);
                }

                OnRaiseTextReceivedEvent(receivedCommunicationMessage);
            }
        }
コード例 #2
0
        public void SendToAuthenticatedClient(CommunicationMessage communicationMessage)
        {
            byte[] textMessageAsBytes;

            try
            {
                AuthenticatedTcpClient clientToSendTo;
                textMessageAsBytes = Encoding.Unicode.GetBytes(CryptographyService.EncryptForNetwork(communicationMessage.BuildCommunicationMessageText()));

                clientToSendTo = allAuthenticatedClients.First(AuthenticatedTcpClient => AuthenticatedTcpClient.ClientID == communicationMessage.RecipientID);
                clientToSendTo.tcpClient.GetStream().WriteAsync(textMessageAsBytes, 0, textMessageAsBytes.Length);

                Array.Clear(textMessageAsBytes, 0, textMessageAsBytes.Length);
            }
            catch (Exception ex)
            {
                string s = ex.Message;
            }
        }
コード例 #3
0
        private void AddAuthenticatedClient(CommunicationMessage receivedCommunicationMessage, TcpClient clientThatConnected)
        {
            if (receivedCommunicationMessage.MessageType == (int)Common.CommunicationMessageType.Login)
            {
                Common.CommunicationAuthenticationData communicationAuthenticationData;
                communicationAuthenticationData.ID             = receivedCommunicationMessage.SenderID;
                communicationAuthenticationData.Authentication = receivedCommunicationMessage.SenderAuthentication;
                communicationAuthenticationData.Type           = (Common.CommunicationClientType)receivedCommunicationMessage.SenderType;

                AuthenticatedTcpClient authenticatedTcpClient = new AuthenticatedTcpClient(communicationAuthenticationData);

                if (authenticatedTcpClient.IsAuthenticated())
                {
                    allConnectedClients.Remove(clientThatConnected);
                    authenticatedTcpClient.tcpClient = clientThatConnected;
                    allAuthenticatedClients.Add(authenticatedTcpClient);
                }
            }
        }
コード例 #4
0
 protected virtual void OnRaisePeerConnectedEvent(CommunicationMessage clientEventArguments)
 {
     RaiseServerConnectedEvent?.Invoke(this, clientEventArguments);
 }
コード例 #5
0
 protected virtual void OnRaiseTextReceivedEvent(CommunicationMessage clientEventArguments)
 {
     RaiseTextReceivedEvent?.Invoke(this, clientEventArguments);
 }
コード例 #6
0
 protected virtual void OnRaiseClientAuthenticatedEvent(CommunicationMessage serverEventArguments)
 {
     RaiseClientAuthenticatedEvent?.Invoke(this, serverEventArguments);
 }
コード例 #7
0
 public void SendToAllAuthenticatedClients(CommunicationMessage communicationMessage)
 {
 }