Help with coding

Mangos

New Member
Joined
Jul 6, 2012
Messages
91
Points
6
Working on a server status updater... it pings the server to check and uhmm idk, its not working. Keeps sending back failure even when servers online. If someone could tell me whats wrong with the code I would appreciate it. Thanks

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;


namespace PWOServerStatus
{
class Program
{
public static Socket Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

static void Main(string[] args)
{
try
{
Console.WriteLine("217.23.6.83");
Console.WriteLine("Coded by Rasta... press enter to continue");
IPAddress IP = IPAddress.Parse(Console.ReadLine());
Console.WriteLine("800");
uint Port = uint.Parse(Console.ReadLine());

Console.WriteLine("");
Console.WriteLine("Connecting....");
Console.WriteLine("217.23.6.83: {0}", IP);
Console.WriteLine("800: {0}", Port);

Server.Connect(IP, (int)Port);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Connected!");
Console.ResetColor();
Console.WriteLine("");
}
catch
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Connection Failed!");
Console.ResetColor();
Console.WriteLine("");
}
Console.WriteLine("Press any key to exit....");
Console.ReadLine();

}
}
}
 

Hardcoreh

New Member
Joined
Mar 10, 2012
Messages
114
Points
16
I'm not really a fan of C#, I don't use it much (if at all), but I suggest using TcpClient for this.

static void Main(string[] args) {
try {
// Read input from console, store it in string IP.
Console.WriteLine("Enter IP address:");//217.23.6.83
string IP = Console.ReadLine();

// Read input from console, store it in unsigned int Port.
Console.WriteLine("Enter port number:");//800
uint Port = uint.Parse(Console.ReadLine());

Console.WriteLine("Connecting....\n");

// Connect to server to see if it's online or not.
TcpClient client = new TcpClient(IP, (int)Port);

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Connected!\n");
Console.ResetColor();
} catch {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Connection Failed!\n");
Console.ResetColor();
}
Console.WriteLine("Press any key to exit....");
Console.ReadLine();
}

Haven't tested this fully, but should do the job.
 

CheckeredZebra

Youngster
Joined
Sep 7, 2011
Messages
2,372
Points
38
I have no idea if this is the same thing or not, so forgive me my ignorance, but depending on how you coded it or not...

Well, a long time ago there was a problem with a status checker. So many different people used it that it started to literally crash the server. Not sure if there are safegaurds against that particular method of coding or not.
 

Hardcoreh

New Member
Joined
Mar 10, 2012
Messages
114
Points
16
risefromruins said:
Why not just check the website's server status checker that does the same thing?
Could be that he/she/it wanted to try to program/learn something instead of using what others already have made.
 

risefromruins

Youngster
Joined
Sep 20, 2011
Messages
2,144
Points
36
Almost all 3rd party applications made for PWO do not end well. I personally never recommend using one because you just don't need it.
 
Top