Hi all,
Have written a simple TCPServer, see code below, that is suppose to listen at a certain port for a message and print that message. If I use for example port 8001, then the code works perfectly. However I need to listen to port 80, for an email with a specific header. When the email with the correct header is received at port 80, I need my code to respond in a specific manner. The problem is that when I try and connect to port 80, I get the following exception:
Any suggestions on why this problem is occuring, I think it might be to do with security related issues.
Mike55.
Have written a simple TCPServer, see code below, that is suppose to listen at a certain port for a message and print that message. If I use for example port 8001, then the code works perfectly. However I need to listen to port 80, for an email with a specific header. When the email with the correct header is received at port 80, I need my code to respond in a specific manner. The problem is that when I try and connect to port 80, I get the following exception:
Code:
Error..... at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at System.Net.Sockets.TcpListener.Start()
at TCPServer.Form1.btnServer_Click(Object sender, EventArgs e) in c:\documents and settings\modonnell.itec\my documents\visual studio projects\tutorials\c-sharp\tcpserver\form1.cs:line 98
Any suggestions on why this problem is occuring, I think it might be to do with security related issues.
Mike55.
Code:
try
{
IPAddress ipAD = IPAddress.Parse("xxx.xxx.x.x");
TcpListener myList = new TcpListener(ipAD, 80);
myList.Start();
Console.WriteLine("The server is running at port 8001");
Console.WriteLine("The local End point is : "+myList.LocalEndpoint);
Console.WriteLine("Waiting for a connection.");
Socket s = myList.AcceptSocket();
Console.WriteLine("Connection Accepted from : "+ s.RemoteEndPoint);
byte [] b=new byte[100];
int k=s.Receive(b);
Console.WriteLine("Received...");
for (int i =0; i<k; i++)
Console.WriteLine(Convert.ToChar(b[i]));
ASCIIEncoding asen=new ASCIIEncoding();
s.Send(asen.GetBytes("The string was recieved by the server."));
Console.WriteLine("\nSent Acknowledgement");
s.Close();
myList.Stop();
}
catch (Exception a)
{
Console.WriteLine("Error..... " + a.StackTrace);
}