简体   繁体   English

如何连接到像PuTTY这样的C#套接字?

[英]How To Connect to a Socket in C# Like PuTTY?

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. 我试图找到一种方法来连接到C#中的套接字,这与使用PuTTY可以实现的方式类似。 For instance, in PuTTy, for my purpose, I would enter the IP and port, select Raw connection type, then open the connection. 例如,出于我的目的,在PuTTy中,我将输入IP和端口,选择Raw连接类型,然后打开连接。 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". 我以为下面的代码可以用,但是它抛出SocketException:“试图以一种其访问权限禁止的方式访问套接字”。

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. 提前致谢。

如果使用SocketType.Raw则必须以admin身份启动程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM