Beispiel #1
0
        ////////////////////////////////////////////////////// //BUTTONS////////////////////////////////////////////////////////////
        private void FindButton_Click(object Psender, RoutedEventArgs e)
        {
            try
            {
                //If the socket is null, create a new one.
                if (SocketClass.GetSocket() == null)
                {
                    SocketClass = new SocketClass();
                }

                ConvoBox.Items.Add("Waiting for a user to connect...");
                ConnectButton.IsEnabled    = false;
                FindButton.IsEnabled       = false;
                DisconnectButton.IsEnabled = true;

                MyUsername = UsernameHost.Text;
                IPEndPoint LocalEp = new IPEndPoint(hostIp, Convert.ToInt32(ListenPort.Text));
                SocketClass.Bind(LocalEp);

                //Starts listening after user to chat with
                SocketClass.Listen(100);
                SocketClass.Accept();

                SocketClass.OnAccept         += new EventHandler(Eventaction_ConnectRequest);
                SocketClass.OnDisconnect     += new EventHandler(Eventaction_DisableButtons);
                SocketClass.OnReceiveMessage += new EventHandler(Eventaction_DisplayMessage);
                SocketClass.OnReceiveImage   += new EventHandler(Eventaction_DisplayImage);
            }
            catch (SocketException ex)
            {
                Eventaction_DisableButtons(null, new EventArgs());
                MessageBox.Show("A socket error occurred: " + ex.ToString());
                Console.WriteLine(ex.StackTrace);
            }
            catch (Exception ex)
            {
                MessageBox.Show("A error occured: " + ex.ToString());
                Console.WriteLine(ex.StackTrace);
            }
        }