无法将类型 string 隐式转换为 System.NET.IPAddress
这是什么意思啊,我要监听一台机的端口,代码如下:
private void listen()
{
bool listenerRun=true;
Regex rx = new Regex(@"^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}");
Match mh = rx.Match(textBox1.Text, 0, textBox1.Text.Length);
if (!mh.Success)
{
MessageBox.Show("你所输入的不是正确的IP信息!", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
textBox1.Focus();
}
try
{
IPAddress ipAddress = textBox1.Text;
TcpListener tcp = new TcpListener(ipAddress,80);
tcp.Start();
statusStrip1.Text = "正在监听......";
while (listenerRun)
{
Socket s = tcp.AcceptSocket();
Byte[] stream = new Byte[80];
int i = s.Receive(stream);
string message = Encoding.UTF8.GetString(stream);
richTextBox1.AppendText(message);
}
}
catch(System.Security.SecurityException)
{
MessageBox.Show("防火墙安全错误!", "错误!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
statusStrip1.Text = "已经停止监听...";
}
}
就是要监听输入在 textBox1.Text这个IP的,出现在上述错误,不会解决,请高手帮忙,谢谢!!