C# TCP Authentication HELP!!

May 14 2009 4:23 AM
ey guys,

So recently I made this simple TCP server. What I want it to do now is, when the employee enters the id, it will go to the server, check it see if it exists -- if not, it simply returns an error message in the console and doesn't load the form. Here is what I have now.

using System;
using System.Text;
using System.Net;
using System.Net.Sockets;

public class serv
{
public static void Main()
{
int c = 1234;
try
{
IPAddress ipAd = IPAddress.Parse("69.10.61.145"); //use local m/c IP address, and use the same in the client

/* Initializes the Listener */
TcpListener myList = new TcpListener(ipAd, 7575);

/* Start Listeneting at the specified port */
myList.Start();

Console.WriteLine("Login Server is running.");
Console.WriteLine("Connection :" + myList.LocalEndpoint);
Console.WriteLine("Waiting for logins...");
Console.WriteLine("================================");

Socket s = myList.AcceptSocket();
Console.WriteLine("Connection accepted from: " + s.RemoteEndPoint);

byte[] b = new byte[100];
int k = s.Receive(b);



Console.WriteLine("Login Attempt Recieved from: " + s.RemoteEndPoint);
for (int i = 0; i < k; i++)
Console.Write(Convert.ToChar(b[i]));


ASCIIEncoding asen = new ASCIIEncoding();






s.Send(asen.GetBytes("Login is invalid." + s.RemoteEndPoint));
Console.WriteLine("\nAccess Denied.");
Console.ReadLine();
return;
/* clean up */
}



catch (Exception e)
{
Console.WriteLine("Error..... " + e.StackTrace);
Console.ReadLine();
}
}

}



I have the client done, I'm willing to manually add the employee id's in there, I just need help with bytes to int's etc.