Пример #1
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            Socket     sck      = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234);

            sck.Connect(endPoint);//connection end point

            user.MySocket = sck;
            //parse username and password from argument
            string username = e.Argument.ToString().Split(':')[0];
            string password = e.Argument.ToString().Split(':')[1];

            //send credentials to Server for validation
            SocketReadWrite.writeToSocket(sck, "signUp:" + username + ":" + "Password:"******"true")
            {
                (sender as BackgroundWorker).ReportProgress(1);
            }
            else
            {
                (sender as BackgroundWorker).ReportProgress(-1);
            }

            // sck.Close();
        }
Пример #2
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            String userName = e.Argument.ToString().Split(':')[0];
            String password = e.Argument.ToString().Split(':')[1];

            Socket     sck      = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1234);

            sck.Connect(endPoint); //connection end point

            user.MySocket = sck;   //add a socket against the user

            //send credentials to Server for authentication
            SocketReadWrite.writeToSocket(sck, "login:"******":" + "Password:"******"true")
            {
                (sender as BackgroundWorker).ReportProgress(1);
            }
            else if (dataReceived == "userAlreadyLoggedIn")
            {
                (sender as BackgroundWorker).ReportProgress(0);
            }
            else
            {
                (sender as BackgroundWorker).ReportProgress(-1);
            }
        }
Пример #3
0
        private void btnLogout_Click(object sender, RoutedEventArgs e)
        {
            CloseAllChatSessionWindows();
            SocketReadWrite.writeToSocket(user.MySocket, "  ");
            SocketReadWrite.writeToSocket(user.MySocket, "Logout:" + user.Username);
            worker.CancelAsync();
            user.MySocket.Shutdown(SocketShutdown.Both);
            user.MySocket.Close();
            this.Close();

            //new LoginWindow().Show();
        }
Пример #4
0
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            rtbChat.AppendText("Me: " + txtMessage.Text + Environment.NewLine);
            rtbChat.FontSize = 15;
            String messageToSend = uniqueIdentifier + ":" + user.Username + ":" + message_to + ":" + " " + txtMessage.Text;

            //Send the message on socket
            if (HasSent == true)
            {
                HasSent = false;
                SocketReadWrite.writeToSocket(user.MySocket, messageToSend);
            }

            SocketReadWrite.writeToSocket(user.MySocket, "  ");//ping
            SocketReadWrite.writeToSocket(user.MySocket, messageToSend);

            File.AppendAllText(user.Username + message_to + ".txt", CryptoEngine.EncryptPlainTextToCipherText("Me: " + txtMessage.Text) + Environment.NewLine);

            txtMessage.Text = ""; //Make text box empty
        }
Пример #5
0
 public void sendAttributesToServer(Socket socket)
 {
     SocketReadWrite.writeToSocket(socket, "  ");
     //Send
     SocketReadWrite.writeToSocket(socket, "newSessionStarted:" + user.Username + ":" + message_to + ":" + uniqueIdentifier);
 }