473,785 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Exception: A socket operation has encountered a dead network

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.Sta rt()
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(ipA ddress,Port);
remoteEP = new IPEndPoint(ipAd dress, Port);
}

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

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

}

}

Jul 8 '07 #1
11 4596
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********@gma il.comwrote in message
news:11******** *************@r 34g2000hsd.goog legroups.com...
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.Sta rt()
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(ipA ddress,Port);
remoteEP = new IPEndPoint(ipAd dress, Port);
}

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

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

}

}


Jul 8 '07 #2
Thanks...

I just wrote one digit wrong in my localhost ip address by mistake.
Jul 9 '07 #3
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********@gma il.comwrote in message
news:11******** *************@g 4g2000hsf.googl egroups.com...
Thanks...

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


Jul 12 '07 #4
On Wed, 11 Jul 2007 21:16:19 -0700, Michael D. Ober
<obermd.@.alum. mit.edu.nospamw rote:
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.
I assumed he meant "127.0.0.1" , the standard "localhost" IP address that
always refers to the local computer.

You're correct that it's possible to get a list of the local IP addresses
assigned to the local computer. However, it's very unusual for an
application to need those. What they need is the addresses of other
computers (and normally this is handled through normal DNS, or explicitly
typing the IP address for those other computers).

In particular (and this is the main reason I'm bothering to reply) most of
the time when someone is getting the list of local IP addresses, it's
because they incorrectly think that they need to give their own IP address
to some remote process. Not only is this not needed, doing so is likely
to break a variety of scenarios, most often involving NAT routers or proxy
servers (since in those cases, the IP address the local computer is aware
of is not the IP address the remote computer needs to use to communicate
with it).

You are probably aware of this, and the OP may even be aware of it but
just in case, I'm posting this information here. If nothing else,
hopefully someone else noticing the advice to get the local IP addresses
will also see this and avoid doing something they shouldn't. :)

Pete
Jul 12 '07 #5
But hey what you told about is a dial-up connection ? or it will work
for cable connection too?

Since, I use cable connection and i have a static IP:

"192.168.0. 71"

Reply Plz

Jul 12 '07 #6
On Wed, 11 Jul 2007 23:28:01 -0700, weird0 <am********@gma il.comwrote:
But hey what you told about is a dial-up connection ? or it will work
for cable connection too?
The API that will get you the installed network adapters' IP addresses
doesn't care what kind of adapter it is. You will get your _local_ IP
address for each adapter (most people usually only have one, but some
computers do have more than one network adapter installed, especially
laptops and newer PCs with 1394 built in, since those are sometimes mapped
to act as a network adapter).

For dial-up, your local IP address is sometimes the public Internet
routable address, and sometimes it's a DHCP address assigned by your ISP
and routed through their own version of a proxy server or NAT router.

If you have a broadband connection and are directly connection,
again...this could either be your public Internet address, or a
DHCP-assigned address routed through your ISP's servers.

If you have a broadband connection and it goes through a router in your
own home, then you are almost certainly using a NAT router and the
computer has a DHCP-assigned address rather than a public IP address.

The above is not even a complete enumeration of all the possibilities.
It's simply an attempt to illustrate the fact that getting your own
locally-assigned IP address is often not very useful, and in the typical
case is not even needed.
Since, I use cable connection and i have a static IP:

"192.168.0. 71"
That's a LAN address, not routable on the Internet. You say it's a static
IP, but if so it's only static within your own LAN. You can use it within
your LAN, but other computers on the Internet won't be able to do anything
useful with that address.

Pete
Jul 12 '07 #7
OP's code was setting up a listener socket. You need one of your local IPs
(other than 127.0.0.1) for an external system to be able to connect to it.
If you use 127.0.0.1 only applications on your local system can connect.

The code to do this without hard coding your IP address is

using System.Net.Sock ets
using System.New

IPAddress ServerAddress = Dns.GetHostEntr y(<string
machinename>).A ddressList[0];
IPEndPoint LocalHost = new IPEndPoint(Serv erAddress, <int port>);
TcpListener tcpServer = new TcpListener(Loc alHost);

In VB 2005, here's working code:
Dim ServerAddress As IPAddress =
Dns.GetHostEntr y(My.Computer.N ame).AddressLis t(0)

Dim LocalHost As New IPEndPoint(Serv erAddress, Port)

tcpServer = New TcpListener(Loc alHost)

Mike.

"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Wed, 11 Jul 2007 21:16:19 -0700, Michael D. Ober
<obermd.@.alum. mit.edu.nospamw rote:
>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.

I assumed he meant "127.0.0.1" , the standard "localhost" IP address that
always refers to the local computer.

You're correct that it's possible to get a list of the local IP addresses
assigned to the local computer. However, it's very unusual for an
application to need those. What they need is the addresses of other
computers (and normally this is handled through normal DNS, or explicitly
typing the IP address for those other computers).

In particular (and this is the main reason I'm bothering to reply) most of
the time when someone is getting the list of local IP addresses, it's
because they incorrectly think that they need to give their own IP address
to some remote process. Not only is this not needed, doing so is likely
to break a variety of scenarios, most often involving NAT routers or proxy
servers (since in those cases, the IP address the local computer is aware
of is not the IP address the remote computer needs to use to communicate
with it).

You are probably aware of this, and the OP may even be aware of it but
just in case, I'm posting this information here. If nothing else,
hopefully someone else noticing the advice to get the local IP addresses
will also see this and avoid doing something they shouldn't. :)

Pete

Jul 12 '07 #8
I wouldn't guarantee any IP address is static unless you are paying extra
for a static address. In that case, you would have a routable address, and
not an address in the 196.168.x.x range. Just because you haven't seen your
address change doesn't mean that it won't.

Mike.
"weird0" <am********@gma il.comwrote in message
news:11******** **************@ 57g2000hsv.goog legroups.com...
But hey what you told about is a dial-up connection ? or it will work
for cable connection too?

Since, I use cable connection and i have a static IP:

"192.168.0. 71"

Reply Plz

Jul 12 '07 #9
On Thu, 12 Jul 2007 07:33:50 -0700, Michael D. Ober
<obermd.@.alum. mit.edu.nospamw rote:
OP's code was setting up a listener socket. You need one of your local
IPs
(other than 127.0.0.1) for an external system to be able to connect to
it.
If you use 127.0.0.1 only applications on your local system can connect.
All true statements. So?

Have you never used your localhost address for testing purposes?

It's not a good idea to specify _any_ specific IP address for a listening
socket anyway. But if one is going to do so, there's nothing
fundamentally wrong with using the localhost address versus some other
locally valid address.
Jul 12 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5134
by: David | last post by:
Hi, Ive been trying to work this out for the past 2 days now and im not getting anywhere fast. The problem i have is that i am using Asynchronous sockets to create a Socket Client library. When i try to connect to a server that doesnt exist it raises a "Connection forcibly rejected by the resmote host" SocketException.
4
3856
by: Frank Meng | last post by:
Hi. I am trying a csharp sample from http://www.codeproject.com/csharp/socketsincs.asp . (Sorry I didn't post all the source codes here, please get the codes from above link if you want to try). I had some troubles when I started 6 threads (each thread made a separate connection) and sent messages to same server simultaneously. Sometimes, not always, the socket looks like ok, but really it is dead. I don't why it happens.
4
2748
by: Qingdong Z. | last post by:
I have an asynchronous Server Socket to push data to client (Socket.BeginSend) when data is available, Meanwhile, the client socket use Synchronous Client Socket to receive the data. I have two questions on this 1. When client socket does not receive data as fast as server, does server socket queues all the data, or just waits? If it queues, this may kill server 2. I declare socket receive buffer big enough, when I call Socket.Receive...
1
1532
by: Simon M | last post by:
Hi, I'm not sure where to post this as it's about windows forms, web forms, socket communication and embedded objects. I am developing a smart client which is embedded in a webform. This client software communicates with a third party windows service over sockets. However I have a weird exception being raised in the AppDomain that I can't handle. When I finish the socket communication (all asyncronous) I popup a modal winform, which...
6
13021
by: Aero | last post by:
Hi, My window application written in C# is throwing following exception while connecting to one FTP location The type initializer for System.Net.Sockets.Socket threw an exception This exe is working fine on staging environment, (Window 2003) but after migrating to production environment (Windows 2000), throwing this exception at
6
27350
Frinavale
by: Frinavale | last post by:
Hi there, I'm not sure if anyone here can help me but I'm pretty desperate at this point. I've developed a web application that sends emails periodically. Everything works fine in the test environment (Visual Studio 2005's server emulator) but not when I publish it to the real IIS server. The IIS server is on the same machine that I am developing on. After reviewing the Windows Event log I discovered that our WinSock firewall is...
10
3589
by: John Nagle | last post by:
Here are three network-related exceptions. These were caught by "except" with no exception type, because none of the more specific exceptions matched. This is what a traceback produced: 1. File "D:\Python24\lib\socket.py", line 295, in read data = self._sock.recv(recv_size) timeout: timed out
2
18381
by: kodart | last post by:
Introduction Performance is the main concern to most server application developers. That’s why many of them anticipate using .NET platform to develop high performance server application regardless of the security features it provides. Microsoft Windows provides a high performance model that uses I/O completion port (IOCP) to process network events. IOCP provides best performance, but difficult to use due to lack of good code samples and...
2
4415
by: senglory | last post by:
My WCF: public interface IWorkbookService { DataTable GetDownpayments(KeyValuePair<int, string> sgm); } class WorkbookService : IWorkbookService
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.