例外:套接字操作遇到死网络 [英] Exception: A socket operation has encountered a dead network

查看:246
本文介绍了例外:套接字操作遇到死网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是c#中socket编程的初学者。我知道如何编程它们的概念

。当我尝试在服务器端编写代码时,我得到了上述异常tcpListener.Start()

当我通过localhost ip和端口号时。 4000:


请帮助...


命名空间服务器

{

class Server

{

TcpListener tcpListener;

IPAddress ipAddress;

IPEndPoint remoteEP;


公共服务器(字符串ipaddress,int端口)

{

ipAddress = IPAddress.Parse(ipaddress);

tcpListener = new TcpListener(ipAddress,Port);

remoteEP = new IPEndPoint(ipAddress,Port);

}


public void开始()

{

试试

{

tcpListener.Start(); //异常线

}

catch(例外情况)

{

MessageBox.Show("问题:+ ex.Message;

}

}


public void Stop()

{

tcpListener.Stop();

}


}


}

I am a beginner to socket programming to in c#. I know the concepts
as to how to program them. I get the above exception when i tried
writing the code for the server side on the line tcpListener.Start()
when i passed the localhost ip and port no. 4000:

Please help...

namespace Server
{
class Server
{
TcpListener tcpListener;
IPAddress ipAddress;
IPEndPoint remoteEP;

public Server(string ipaddress, int Port)
{
ipAddress = IPAddress.Parse(ipaddress);
tcpListener = new TcpListener(ipAddress,Port);
remoteEP = new IPEndPoint(ipAddress, Port);
}

public void Start()
{
try
{
tcpListener.Start(); // line of exception
}
catch (Exception ex)
{
MessageBox.Show("Problem:" + ex.Message);
}
}

public void Stop()
{
tcpListener.Stop();
}

}

}

推荐答案

什么是ipaddress?如果这是一个对本地

机器无效的地址,你会得到这个例外。


Mike Ober。


" weird0" < am ******** @ gmail.comwrote in message

news:11 ********************* @ r34g2000hsd.googlegro ups.com ...
What is "ipaddress"? If it is an address that isn''t valid for the local
machine, you will get this exception.

Mike Ober.

"weird0" <am********@gmail.comwrote in message
news:11*********************@r34g2000hsd.googlegro ups.com...

我是c#中socket编程的初学者。我知道如何编程它们的概念

。当我尝试在服务器端编写代码时,我得到了上述异常tcpListener.Start()

当我通过localhost ip和端口号时。 4000:


请帮助...


命名空间服务器

{

class Server

{

TcpListener tcpListener;

IPAddress ipAddress;

IPEndPoint remoteEP;


公共服务器(字符串ipaddress,int端口)

{

ipAddress = IPAddress.Parse(ipaddress);

tcpListener = new TcpListener(ipAddress,Port);

remoteEP = new IPEndPoint(ipAddress,Port);

}


public void开始()

{

试试

{

tcpListener.Start(); //异常线

}

catch(例外情况)

{

MessageBox.Show("问题:+ ex.Message;

}

}


public void Stop()

{

tcpListener.Stop();

}


}


}
I am a beginner to socket programming to in c#. I know the concepts
as to how to program them. I get the above exception when i tried
writing the code for the server side on the line tcpListener.Start()
when i passed the localhost ip and port no. 4000:

Please help...

namespace Server
{
class Server
{
TcpListener tcpListener;
IPAddress ipAddress;
IPEndPoint remoteEP;

public Server(string ipaddress, int Port)
{
ipAddress = IPAddress.Parse(ipaddress);
tcpListener = new TcpListener(ipAddress,Port);
remoteEP = new IPEndPoint(ipAddress, Port);
}

public void Start()
{
try
{
tcpListener.Start(); // line of exception
}
catch (Exception ex)
{
MessageBox.Show("Problem:" + ex.Message);
}
}

public void Stop()
{
tcpListener.Stop();
}

}

}






谢谢...


我刚刚写了一个错误地在我的localhost ip地址错误。
Thanks...

I just wrote one digit wrong in my localhost ip address by mistake.


扫描Socket类,你会发现一个返回

本地列表的方法IP地址。如果您使用此方法获取本地计算机的IP地址

,那么您将避免错误输入您的

本地地址以及允许您的代码的整个问题在不同的系统上工作或者

网络。


迈克。


" weird0" < am ******** @ gmail.comwrote in message

news:11 ********************* @ g4g2000hsf.googlegrou ps.com ...
Scan through the Socket classes and you will find a method that returns a
list of local IP addresses. If you use this method to get the IP address
for the local machine, you will avoid then entire issue of mis-typing your
local address as well as allow your code to work on a different system or
network.

Mike.

"weird0" <am********@gmail.comwrote in message
news:11*********************@g4g2000hsf.googlegrou ps.com...

谢谢...


我刚写了一个错误的本地主机错误的IP地址。
Thanks...

I just wrote one digit wrong in my localhost ip address by mistake.






这篇关于例外:套接字操作遇到死网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆