提供了无效的参数(套接字) [英] An invalid argument was supplied (Socket)

查看:176
本文介绍了提供了无效的参数(套接字)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到FTP服务器,因此仅一次建立了连接,而我想打开多个连接并使用线程上传多个文件.一切正常,仅当我上传单个文件时. (1比1).


连接到FTP Server时打开多个连接时出现错误.

I am trying to Connect to FTP Server, well the connection is established only once, while I want to open multiple connections and upload multiple files using threading. everything works fine Only if I upload single file. (1 by 1).


The error appears while connecting to FTP Server opening multiple connections.

protected bool login()
{
    bool connected = false;
    try
    {
         IPEndPoint ip = new IPEndPoint(Dns.Resolve(ftpAddress).AddressList[0],ftpPort); //PORT = 21
         socket.Connect(ip); //The error occurs in this statement
     }
     catch (Exception ex)
     {
         Debug.Write(ex.Message);
     }
     return connected;
}


并且出现错误"提供了无效的参数FTP服务器IP "

我用谷歌搜索,但是没有解决方案.

我很高兴了解如果打开与ftp服务器的多个连接为什么会出现错误?


and I am getting the error "An invalid argument was supplied FTP SERVER IP"

I googled but no solution helped.

I do appreciate to understand why the error appears if I open multiple connection to ftp server?

推荐答案

来自
From the MSDN page[^] for Socket.Connect:


您可以使用 SocketException.ErrorCode 来获取特定的错误代码.获取此代码后,请参阅MSDN库中的Windows套接字版本2 API错误代码文档,以获取有关该错误的详细说明.

You can use SocketException.ErrorCode to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.



您尝试过吗?



Have you tried that?


您只能使用同一套接字连接一次.您似乎正在使用实例变量"socket",因此,当您调用login时,第二次套接字已连接,因此再次尝试连接将失败.

要打开多个连接,您需要创建多个套接字.
You can only connect once using the same socket. You appear to be using an instance variable ''socket'' and therefore when you call login the second time socket is already connected, so trying to connect again will fail.

To open multiple connections you need to create multiple sockets.


这篇关于提供了无效的参数(套接字)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆