c# - 我该如何解决有关 TcpListener : Please use TcpListener(IPAddress localaddr, int port) 的警告?

标签 c# .net winforms sockets networking

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

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);

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

警告 4 'System.Net.Sockets.TcpListener.TcpListener(int)' is obsolete: '"This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead.

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

最佳答案

var serverSocket = new TcpListener(IPAddress.Any, 8888);

关于c# - 我该如何解决有关 TcpListener : Please use TcpListener(IPAddress localaddr, int port) 的警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28155702/

相关文章:

c# - .net MVC 中的网络摄像头集成

c# - 使用 Sort() 按特定条件对列表数据进行排序,

c# - 计算每月百分比

c# - 如何限制 DateTimePicker 只更改日期,而不更改时间?

c# - 带下拉菜单的 Windows.Forms 按钮

c# - 从 ASP.NET Core 中的 ViewComponent 提交表单并执行 Controller 操作

c# - Nlog 可以定位 Azure Log Analytics 吗?

c# - 无法从传输连接读取数据 : An established connection was aborted by the software in your host machine in C# .Net

.net - Interop.Excel.PivotTable 的好教程

c# - 如何在 C# 中制作自定义控件?