【问题标题】:How can i solve the warning about TcpListener: Please use TcpListener(IPAddress localaddr, int port) instead?如何解决有关 TcpListener 的警告:请改用 TcpListener(IPAddress localaddr, int port)?
【发布时间】:2015-03-25 04:41:28
【问题描述】:

我创建了一个新表单,在顶部我做了:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Collections;
using System.Net.Sockets;

namespace mws
{
    public partial class Chat : Form
    {
        TcpListener serverSocket = new TcpListener(8888);

在 new TcpListener(8888) 下,我看到绿线,警告是:

警告 4 'System.Net.Sockets.TcpListener.TcpListener(int)' is obsolete: '"此方法已被弃用。请改用 TcpListener(IPAddress localaddr, int port)。

尝试谷歌,但我没有找到任何解决方案。 尝试做:new TcpListener(8888,21) 可能使用端口,但这不是解决方案。

【问题讨论】:

  • 我猜向下滚动到example 太多了?
  • 如果这个例子像@Bull Durham 的答案一样苗条,那会有所帮助

标签: c# .net winforms sockets networking


【解决方案1】:
var serverSocket = new TcpListener(IPAddress.Any, 8888);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-28
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-15
    相关资源
    最近更新 更多