HI,
Does anyone know why I get this error message: "attempt was made to access a socket in a way forbidden by its access permission"
Using Visual Studio .Net & C#, I have a simple "Hello World" webservice which is running on my http://localhost/trial5. And I have another Console Application project that acts as a listener and continues on listening on port 80 for any incoming traffic.
I am trying to have my listener trap any incoming traffic on that port for additional analyzing of data, but when I try to run it to start listening, I get the error above. Is this an administrative fix If so, how can I fix it
Worth mentioning is that my web service project is of type "HTTP" created by VS. Net 2005. Here is the code of both projects (different solutions).
Your help is greatly appreciated!!
//Web Service code
namespace
trial6{
[
WebService(Namespace = "http://tempuri.org/")][
WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService{
public Service(){
//Uncomment the following line if using designed components //InitializeComponent();}
[
WebMethod] public string HelloWorld(){
return "Hello World";}
}
}
// MY Listener code:
using
System;using
System.Collections.Generic;using
System.Text;using
System.Net.Sockets;using
System.Net;using
System.Threading;namespace
ConsoleApplication2{
class Program{
static bool pause = false; static bool canStopListening = false; static Thread t1 = new Thread(new ThreadStart(Listen)); static void Main(string[] args){
Listen();
}
private static void Listen(){
const int portNo = 80; IPAddress localAdd = IPAddress.Parse("127.0.0.1"); TcpListener listener = new TcpListener(localAdd, portNo);listener.Start();
while (!canStopListening){
if (!pause){
TcpClient tcpc = listener.AcceptTcpClient(); NetworkStream nws = tcpc.GetStream(); byte[] b = new byte[tcpc.ReceiveBufferSize]; // Read the incomin stream. int nBR = nws.Read(b, 0, tcpc.ReceiveBufferSize); // Respond to client. byte[] b2 = Encoding.ASCII.GetBytes("Help Arrived!!!");nws.Write(b2, 0, b2.Length);
tcpc.Close();
}
}
listener.Stop();
}
}
}

Scoket access error
alan666
I think there is some problem accessing the port 80 because you know it's already used by HTTP.
Try to use HTTP Listener for this purpose and see what happens. I think it'll allow you to listen on port 80.
I have not used or done the thing you are trying to do but Its my general observation that may help.
Best Regards,