Listening to Port 80

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
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:

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);
}
 
PlausiblyDamp said:
Is IIS running on the PC? If so then it will be using port 80. Why are you expecting an e-mail on port 80 anyway?

My fault, got the port numbers mixed up, need to listen to port 25 and 110. Can connect to and listen to 110, but not 25. Any suggestions??
 
PlausiblyDamp said:
Again does the PC have the SMTP service running? If so it will grab port 25.

Ok, see what you mean. Is it anyway possible for my program to share port 25 with ISS SMTP??

Mike55
 
mike55 said:
Ok, see what you mean. Is it anyway possible for my program to share port 25 with ISS SMTP??

Mike55
A port is virtual. It is simply a "process identifier" -- meaning it can only identify a single process at a time.
 
Back
Top