Exemple #1
0
        /// <summary>
        /// Try to connect when the user clicks the connect button.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            if (serverTextBox.Text == "")
            {
                MessageBox.Show("You didn't enter a server address, try again.", "Warning!");
                return;
            }

            if (nameTextBox.Text == "")
            {
                MessageBox.Show("Please enter a name!", "Warning!");
                return;
            }

            // Disable serverTextBox, nameTextBox and connectButton
            connectButton.Enabled = false;
            serverTextBox.Enabled = false;
            nameTextBox.Enabled   = false;

            try
            {
                // Connect to the server, specifying the first thing we want to do once a connection is made is FirstContact
                theServer = Networking.ConnectToServer(FirstContact, serverTextBox.Text);   //callMe delegate and IPaddress.
            }
            catch (Exception)
            {
                NetworkError();
            }
        }
Exemple #2
0
        //                                      Controls
        //--------------------------------------------------------------------------------------------

        /// <summary>
        /// Makes the initial connection to the server.
        /// </summary>
        /// <param name="sender">How key was pressed</param>
        /// <param name="e">Event carried with click</param>
        private void button_Connect_Click(object sender, EventArgs e)
        {
            // Empty Server address.
            if (textBox_Server.Text == "")
            {
                MessageBox.Show("Please enter a server address");
                return;
            }

            // Disable the controls and try to connect
            button_Connect.Enabled  = false;
            textBox_Server.Enabled  = false;
            textBox_Name.Enabled    = false;
            button_Controls.Enabled = false;

            // Connect with server, if unsuccessful, reset
            try
            {
                Networking.ConnectToServer(FirstContact, textBox_Server.Text);
            }
            catch
            {
                button_Connect.Enabled  = true;
                textBox_Server.Enabled  = true;
                textBox_Name.Enabled    = true;
                button_Controls.Enabled = true;

                MessageBox.Show("The server adress you entered is unreachable");
            }
        }
 /// <summary>
 /// When the Connect button is clicked, the clientwill connect to the server address specified in the server text box.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ConnectButton_Click(object sender, EventArgs e)
 {
     Networking.ConnectToServer(FirstContact, serverTextBox.Text);
     connectButton.Enabled   = false;
     usernameTextBox.Enabled = false;
     serverTextBox.Enabled   = false;
 }
Exemple #4
0
        /// <summary>
        /// Shows a dialog box for getting the IP address of the spreadsheet server, and connecting appropriately.
        /// </summary>
        private void IPInputBox()
        {
            window.StartPanelTimer();

            // if we have connected to a server previously, we need to disconnect and reset Server...
            if (theServer != null)
            {
                Networking.Send(theServer, "unfocus " + THREE);
                Networking.Send(theServer, "disconnect " + THREE);
                EndSession("RESTART");
            }

            Form2 getIP = new Form2();

            if (getIP.ShowDialog() == DialogResult.OK)
            {
                string ipAddress = getIP.ipTextBox.Text;

                try
                {
                    theServer = Networking.ConnectToServer(FirstContact, ipAddress);
                }
                catch (Exception)
                {
                    EndSession("CONNECTION_ERROR");
                }
            }

            getIP.Dispose();
        }
 // Main method to connect to the server
 public bool connectToServer(string hostName, string name)
 {
     //Use the Networking method to connect to the server
     Networking.ConnectToServer(ServerConnected, hostName, 11000);
     Constants.playerName = name;
     return(true);
 }
Exemple #6
0
        private void Connect_Click(object sender, EventArgs e)
        {
            if (SeverInput.Text == "" || messages.Text == "")
            {
                MessageBox.Show("please enter server address or name");
                return;
            }
            //Disable button after connecting to server
            Connect.Enabled    = false;
            SeverInput.Enabled = false;
            Connect.Visible    = false;
            SeverInput.Visible = false;
            messages.Visible   = false;

            theServer = Networking.ConnectToServer(FirstContact, SeverInput.Text);

            string message = messages.Text;

            //append a newLine since that is our protocal'p terminating characters for a message

            byte[] messageBytes = Encoding.UTF8.GetBytes(message + "\n");
            //messages.Text = "";
            try
            {
                theServer.BeginSend(messageBytes, 0, messageBytes.Length, SocketFlags.None, sendCallBack, theServer);
                this.Focus();
                messages.Enabled = false;
            }catch (Exception)
            {
            }
        }
        private void LoginButton_Click(object sender, EventArgs e)
        {
            if (ServerNameTextBox.Text != "Server Name" && ServerNameTextBox.Text.Length != 0)
            {
                CreateMenu                = true;
                LoginButton.Enabled       = false;
                ServerNameTextBox.Enabled = false;

                try
                {
                    Networking.ConnectToServer(firstContact, ServerNameTextBox.Text);
                    //WindowState = FormWindowState.Minimized;
                }
                catch
                {
                    MessageBox.Show("Unable to connect to server.");
                    LoginButton.Enabled       = true;
                    ServerNameTextBox.Enabled = true;
                    //WindowState = FormWindowState.Normal;
                }

                LoginButton.Enabled       = true;
                ServerNameTextBox.Enabled = true;
            }
        }
 /// <summary>
 /// this method is invoked when the button is clicked.
 /// </summary>
 /// <param name="textBox1"></param>
 public void click(string textBox1)
 {
     try
     {
         this.socket = Networking.ConnectToServer(FirstContact, textBox1);
     }
     catch (Exception e)
     {
     }
 }
Exemple #9
0
        // Connect button event handler
        private void connectButton_Click(object sender, EventArgs e)
        {
            string ip = serverAddress.Text;

            // disconnect from a previous socket
            if (theServer != null)
            {
                if (theServer.connectionEstablished)
                {
                    Networking.Disconnect(theServer);
                }
            }
            try
            {
                theServer = Networking.ConnectToServer(FirstContact, Networking.IPResolve(ip), 11000);
            }
            catch { }
        }
Exemple #10
0
        private void Connect(string ip)
        {
            try
            {
                // Establish the remote endpoint for the socket.
                IPHostEntry ipHostInfo;
                IPAddress   ipAddress = IPAddress.None;

                // Determine if the server address is a URL or an IP
                try
                {
                    ipHostInfo = Dns.GetHostEntry(ip);
                    bool foundIPV4 = false;
                    foreach (IPAddress addr in ipHostInfo.AddressList)
                    {
                        if (addr.AddressFamily != AddressFamily.InterNetworkV6)
                        {
                            foundIPV4 = true;
                            ipAddress = addr;
                            break;
                        }
                    }
                    // Didn't find any IPV4 addresses
                    if (!foundIPV4)
                    {
                        System.Diagnostics.Debug.WriteLine("Invalid addres: " + ip);
                        return;
                    }
                }
                catch (Exception e1)
                {
                    // see if host name is actually an ipaddress, i.e., 155.99.123.456
                    System.Diagnostics.Debug.WriteLine("using IP");
                    ipAddress = IPAddress.Parse(ip);
                }

                theServer = Networking.ConnectToServer(FirstContact, ipAddress);
            }
            catch (Exception e)
            {
            }
        }
 /// <summary>
 /// Instantiates a connection with the server
 /// </summary>
 /// <param name="ip">The host address of the server</param>
 /// <param name="name">The playerID sent to the server</param>
 public void Connect(String ip)
 {
     // If the name or ip is invalid, inform the view that the connection failed
     if (ip.Length == 0 /*|| username.Length == 0 || password.Length == 0*/)
     {
         InformViewConnectionFailed();
     }
     else
     {
         try
         {
             // Try connecting to the server
             socket = Networking.ConnectToServer(ip, FirstContact);
         }
         catch (Exception)
         {
             InformViewConnectionFailed();
         }
     }
 }
Exemple #12
0
        /// <summary>
        /// An Event Handler for when the player hits the 'Go' button trying to connect to a server
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Connect(object sender, EventArgs e)
        {
            // Check to make sure we have valid name
            if (NameBox.Text == "")
            {
                // Display Error
                MessageBox.Show("Please enter a nonempty name");
                return;
            }

            // Check to make sure we have valid Address
            if (ServerBox.Text == "")
            {
                // Display Error
                MessageBox.Show("Please enter a nonempty address");
                return;
            }

            // Sets previous incomplete message received to the empty string
            prevStringHead = "";

            // Gets the address the player wishes to connect to
            string Address = ServerBox.Text;

            try {
                //Establishes a socket with the server, instructing it to get initial data.
                theServer = Networking.ConnectToServer(FirstContact, Address);
            }
            catch (Exception)
            {
                // Display Error
                MessageBox.Show("We could not connect to the server.  Please check yo self before you, inadvertantly, wreck yo self");
                return;
            }

            // Deactivates the button and the textboxes while playing
            ConnectButton.Enabled = false;
            NameBox.Enabled       = false;
            ServerBox.Enabled     = false;
        }
Exemple #13
0
 public static void Connect(
     string serverAddr,
     Action <Client> onConnected,
     Action <Client, string> onReceived,
     Action <Client> onDisconnected
     )
 {
     Networking.ConnectToServer(
         state =>
     {
         if (state.ErrorOccurred)
         {
             onConnected(null);
         }
         else
         {
             onConnected(new Client(state, onReceived, onDisconnected));
         }
     },
         serverAddr,
         Port
         );
 }
 /// <summary>
 /// wrapper for the networking.connecttoserver
 /// </summary>
 /// <param name="address"></param>
 public void Connect(string address)
 {
     Networking.ConnectToServer(OnConnect, address, 11000);
 }
Exemple #15
0
 /// <summary>
 ///     Connects client to server with username and begins Handshake with the server
 /// </summary>
 /// <param name="name">Username</param>
 /// <param name="serverIP">Ip to connect to</param>
 public void Connect(string name, string serverIP)
 {
     _username = name;
     Networking.ConnectToServer(OnConnect, serverIP, Port);
 }
 public void Connect(string ipAddr)
 {
     theServer = Networking.ConnectToServer(StartUp, ipAddr);
 }
Exemple #17
0
 private void ConnectButton_Click(object sender, EventArgs e)
 {
     theServer = Networking.ConnectToServer(FirstContact, HostTextBox.Text);
 }
Exemple #18
0
 /// <summary>
 /// Method used to connect the game to a server to be played on using port 11000
 /// </summary>
 /// <param name="hostname">The domain the game will try to access</param>
 public void ConnectToServer(string hostname)
 {
     Networking.ConnectToServer(OnConnect, hostname, 11000);
 }
Exemple #19
0
 public Program()
 {
     System.Threading.Thread.Sleep(5000);
     theServer = Networking.ConnectToServer(FirstContact, Networking.IPResolve("localhost"));
 }
 private void SpreadsheetClosed(SocketState socket)
 {
     Networking.ConnectToServer(Reconnect, ServerNameLabel.Text);
 }