问题描述
我创建了一个新表单,在顶部我做了:
I created a new form and at the top i did:
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) 下,我看到绿线,警告是:
Under new TcpListener(8888) i see green line and the warning is:
警告 4 'System.Net.Sockets.TcpListener.TcpListener(int)' is obsolete: '"此方法已被弃用.请改用 TcpListener(IPAddress localaddr, int port).
Warning 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) 可能使用端口,但这不是解决方案.
Tried to google but i didn't find any solution.Tried to do: new TcpListener(8888,21) maybe usig a port but this is a not a solution.
推荐答案
var serverSocket = new TcpListener(IPAddress.Any, 8888);
这篇关于如何解决有关 TcpListener 的警告:请改用 TcpListener(IPAddress localaddr, int port)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!