c# - "Either the application has not called WSAStartup, or WSAStartup failed"是什么意思?

标签 c# sockets networking dongle wsastartup

我正在尝试开发通过网络连接到网络服务器的软件;一切正常,直到尝试使用加密狗来保护我的软件。我的加密狗有一些网络功能,它的 API 在网络基础设施下工作。 w当我将 Dongle 检查代码添加到我的程序时,我得到了这个错误:

"Either the application has not called WSAStartup, or WSAStartup failed"  

我放置了抛出异常的代码块。我得到异常(exception)的情况是;我登录到程序(一切正常),然后拔下加密狗,然后程序停止并请求加密狗,我再次插入加密狗并尝试登录,但在线出现异常

response = (HttpWebResponse)request.GetResponse();

DongleService unikey = new DongleService();

                checkDongle = unikey.isConnectedNow();

                if (checkDongle)
                {
                    isPass = true;
                    this.username = txtbxUser.Text;
                    this.pass = txtbxPass.Text;
                    this.IP = combobxServer.Text;
                    string uri = @"https://" + combobxServer.Text + ":5002num_events=1";
                    request = (HttpWebRequest)WebRequest.Create(uri);
                    request.Proxy = null;
                    request.Credentials = new NetworkCredential(this.username, this.pass);
                    ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
                    response = (HttpWebResponse)request.GetResponse();

                    Properties.Settings.Default.User = txtbxUser.Text;
                    int index = _servers.FindIndex(p => p == combobxServer.Text);
                    if (index == -1)
                    {
                        _servers.Add(combobxServer.Text);
                        Config_Save.SaveServers(_servers);
                        _servers = Config_Save.LoadServers();
                    }

                    Properties.Settings.Default.Server = combobxServer.Text;
                    // also save the password
                    if (checkBox1.CheckState.ToString() == "Checked")
                        Properties.Settings.Default.Pass = txtbxPass.Text;

                    Properties.Settings.Default.settingLoginUsername = this.username;
                    Properties.Settings.Default.settingLoginPassword = this.pass;
                    Properties.Settings.Default.settingLoginPort = "5002";
                    Properties.Settings.Default.settingLoginIP = this.IP;
                    Properties.Settings.Default.isLogin = "guest";

                    Properties.Settings.Default.Save();
                    response.Close();
                    request.Abort();
                    this.isPass = true;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Please Insert Correct Dongle!", "Dongle Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }

最佳答案

WSAStartup 是套接字库中的第一个函数,它在开始使用 net 时执行。您可以导入

 [DllImport("ws2_32.dll", CharSet = CharSet.Auto, SetLastError=true)]
 static extern Int32 WSAGetLastError();

当出现异常时,执行 WSAGetLastError 并查看来自 here 的错误代码.希望它能帮助你。在您获得 Win32Exception 的特定情况下,您可以使用异常中的 NativeErrorCode,如 @Patrick 的注释中所写.

关于c# - "Either the application has not called WSAStartup, or WSAStartup failed"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12542287/

相关文章:

c# - 使用 .NET 填充 html 列表控件

java - 后 ICS 版本中的蓝牙连接问题

macos - 装有Docker Toolbox的Mac OSX上的Docker中的端口映射

c# - SmtpClient 可扩展性问题(仅运行两个请求)

Java 安卓 OutputStreamWriter IOException

c# - 在锁屏下运行 Windows Phone 8.1 RT 应用程序

c# - 使用 itextsharp 将 HTML 转换为 PDF

java - android中局域网内广播消息

c# - 什么时候图书馆应该被称为 "Linq-something"或 "something-Linq"?

c - 为了将 tcp 程序转换为 udp 需要进行哪些更改