Beispiel #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();
        }
Beispiel #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);
            }
        }