在同一PC套接字上运行服务器和客户端错误10060

时间:2020-01-22 02:35:05

标签: sockets networking tcp supersocket.net

我有服务器和客户端程序。

在同一台PC上使用时,这是10060错误。(仅几台PC)

这是服务器代码。

public async Task<bool> StartAsync(int port, CancellationToken cancellationToken = default)
    {
        ServerConfig s = new ServerConfig();
        s.Ip = "Any";
        s.Port = 3333;
        s.Mode = SocketMode.Tcp;
        s.TextEncoding = "UTF-8";

        // setup
        if (!await Task.Run(() => Setup(s), cancellationToken))
        {
            var showFalseConfig = Config;
            // failed Setup return to false
            return false;
        }
        // Start
        return await Task.Run(() => Start(), cancellationToken);
    }

这是客户代码。

public async Task<bool> ConnectAsync(CancellationToken cancellationToken = default)
    {
        try
        {
            _client = new EasyClient();
            _client.Initialize(new MyReceiveFilter(), p => Received?.Invoke(this, p));
            _client.Error += ConnectionError;
            _client.Connected += Connected;
            _client.Closed += Closed;
            _client.Closed += Client_Closed;

            return await _client.ConnectAsync(new DnsEndPoint("127.0.0.1", 3333));
        }
        catch(Exception e)
        {
            errorMessage = e.ToString();
            return false;
        }
    }

我认为这段代码没有任何问题。

出什么问题了?

0 个答案:

没有答案