Post: C# Checking Online Availability with IP and Port
08-11-2013, 06:19 AM #1
Default Avatar
Oneup
Guest
(adsbygoogle = window.adsbygoogle || []).push({});
    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();



}

}

}


You must login or register to view this content.
(adsbygoogle = window.adsbygoogle || []).push({});

The following user thanked Oneup for this useful post:

Asian
08-11-2013, 08:26 AM #2
Pichu
RIP PICHU.
Originally posted by UP View Post
    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();



}

}

}


You must login or register to view this content.


Although I'm not entirely sure; 127.0.0.1 is localhost which should always remain active. I'm not sure what you are aiming for or if you are determining if it is available to use.

Little curious as to what this actually entails.
08-11-2013, 08:38 AM #3
Default Avatar
Oneup
Guest
Originally posted by Pichu View Post
Although I'm not entirely sure; 127.0.0.1 is localhost which should always remain active. I'm not sure what you are aiming for or if you are determining if it is available to use.

Little curious as to what this actually entails.


It's a placeholder so you have an idea of what to put there. If you had a server or something that and you wanted to make sure it was still running. You would change 127.0.0.1 for the actual IP and port 80 for the port number.

The following user thanked Oneup for this useful post:

Pichu
08-11-2013, 08:50 AM #4
Pichu
RIP PICHU.
Originally posted by UP View Post
It's a placeholder so you have an idea of what to put there. If you had a server or something that and you wanted to make sure it was still running. You would change 127.0.0.1 for the actual IP and port 80 for the port number.


Ah, ok. I see what you mean here. That's actually quite interesting. ^_^

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo