0

Forgive me, but I am quite a newbie when it comes to this. I am trying to find a way to connect to a socket in C# similar to what I would be able to do with PuTTY. For instance, in PuTTy, for my purpose, I would enter the IP and port, select Raw connection type, then open the connection. I thought the below code would work, but it throws a SocketException saying "An attempt was made to access a socket in a way forbidden by its access permissions".

class Class_1
{
    static void Main(string[] args)
    {
        Socket socket = new Socket(SocketType.Raw, ProtocolType.Tcp);
        /*
         * Below is not the actual IP and port I am using, of course.
         * It is simply for illustrative purposes.
         */
        socket.Connect(new IPAddress(new byte[] { 1, 1, 1, 1 }), 1);
        Console.WriteLine(socket.Poll(10000000, SelectMode.SelectRead));
        Console.Read();
    }
}

Any help would be most appreciate. Thanks in advance.

Joseph Farrar
  • 144
  • 1
  • 1
  • 12
  • 1
    I would be surprised if there were something on the other end listening at the IP 1.1.1.1. You'll need to substitute the IP address of a Putty server you have access to. – Eric J. Oct 09 '15 at 22:08
  • Sorry. To be clear, I am not actually trying to connect to 1.1.1.1:1, I am just using that as a placeholder for the illustrative purpose. Also, as I do not know how to now edit my post, a bit more info: The exception occurs in the very first line when creating the new Socket object. – Joseph Farrar Oct 09 '15 at 22:10
  • Possible duplicate of [An attempt was made to access a socket in a way forbidden by its access permissions](http://stackoverflow.com/questions/15619921/an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissi) – jmoerdyk Oct 09 '15 at 22:13

1 Answers1

1

You have to start the program as admin if you are using SocketType.Raw

Muraad Nofal
  • 794
  • 3
  • 6