ALERT!
Click here to register with a few steps and explore all our cool stuff we have to offer!
Home
Upgrade
Credits
Help
Search
Awards
Achievements
 4147

C# Checking Online Availability with IP and Port

by 1UP - 10-10-2016 - 11:36 PM
#1
Code:
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net.Sockets;

namespace CSharpCheckingOnlineAvailabilityIPPort

{

   public partial class Form1 : Form

   {

       public Form1()

       {

           InitializeComponent();

       }

       private void btn_CheckServer_Click(object sender, EventArgs e)

       {

           TcpClient logonServer = new TcpClient();

           try

           {

               logonServer.Connect("127.0.0.1", 80); //this is just your loop back and checking to see if port 80 is open swap out for whatever you want

           }

           catch (Exception ex)

           {

           

           }

           if (logonServer.Connected)

               this.Text = "Connected";

           else

               this.Text = "Not connected";

           logonServer.Close();

 

       }

   }

}

Source Code
Reply
#2
Great share! Thank you for the code and the source. Heart
Are you a guest to this site? Click the image below and sign up today!
[Image: FTYbRmR.gif]
Reply
#3
Great of you to start off with tutorials. Much appreciated man.
Reply

Users browsing: 1 Guest(s)