473,795 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket shuts down unexpectedly

SBC
Hello,

I have developed a windows service using C#, TcpListener class and its only
function is to listen for clients to connect and send back a respsonse. I
have a customer who states that everyday they need to restart the service so
that the application starts listening on the sockets again.

I have not been able to recreate this situation and don't know why the
socket would shutdown. Can anyone point me to a reason why sockets would
shutdown unexpectedly?

Within the constructor I create a new TcpListener object...

<start of code snippet>
//start listing on the given port
port = Convert.ToInt32 (sPort);
_tcpListener = new TcpListener(ipA ddress, port) ;
_tcpListener.St art();

//start the thread which calls the method 'StartListen'
m_thread = new Thread(new ThreadStart(Sta rtListen));
m_thread.Start( ) ;
<end of code snippet>
in my next snippet for "StartListe n" I wait until a client connects...
<Start Snippet>
StartListen()
{
// variables here...
while(true)
{
// Accept a new connection
Socket _clientSocket = _tcpListener.Ac ceptSocket();
if (_clientSocket. Connected)
{
// At this point we have another application that does logging since the
windows
// service does not have a user interface...
TcpClient _tcpClient = new TcpClient();
try
{
_tcpClient.Conn ect(ipAddress, port)
NetworkStream ns = _tcpClient.GetS tream();
BinaryWriter bw = new BinaryWriter(ns );
bw.Write(sb.ToS tring());
_tcpClient.Clos e();
sb.Remove(0, sb.Length); // sb is a StringBuilder
}
catch(Exception ex)
{
// stuff
}
}
}
One of the things I have recently read is that I need to close the
NetworkStream also, do you think this would cause the sockets to shutdown?
So far I don't receive any types of error messages, the socket just seems to
stop communicating and the windows service needs to be rebooted...

Thank you for your time and help.

Nov 17 '05 #1
0 1275

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

Similar topics

1
7624
by: Tim Gosselin | last post by:
I am writing a tcp tunnel but cannot find a way of detecting when a socket shuts down its read end without writing to the socket. For testing the write end of the remote endpoint I just do a: if not sock.recv(buffsize) I cannot write to the socket and check if send returns 0 though, because that involves sending data out of the which may not have come in yet. When I try polling the socket with:
3
13916
by: Magnus Lycka | last post by:
I have a socket server like below which I want to exit when it's out of data. If I interrupt the client, I'll get a broken pipe on the server side, and after a Ctrl-C, I can restart the server again, but if I let it run out of data, and exit via handle_error as can be seen below, I will get a socket.error: (98, 'Address already in use') when I try to restart the server. (Unless I wait a minute or so, or use another port.) I feel like I'm...
0
917
by: kevin | last post by:
Hello all, I am hoping someone could point me in the right direction. I am working on a project that requires my client socket to maintain an active connection and reply to information form my server at long intervals. The server "pings" the client on a regular basis when there has been no activity in order to ascertain whether or not the connection is still active. it sends the client a particular bit of information and waits for a...
5
45062
by: Morten | last post by:
How do I detect if a client socket is no longer connected to the listen tcp socket ? I have tried with (just an example): --------------------- Socket tcpSocket; while(tcpSocket.Connected)
1
3398
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows XP. About the architecture: I have a socket server dll that contains a class that handles connections for a given local ipaddress and port. This class(server) can be started or stopped by calls to the appropriate functions. The server class has...
2
2727
by: Qindong Zhang | last post by:
My socket application blocked at socket.receiver() after received all information from sender. Should socket.Receive() return 0 after no more data available? Note: My socket object was not close on both client/server side. My cached for further use. While bytesReceived > 0 byteBuffer = New Byte(1024) {} bytesReceived = handler.Receive(byteBuffer) If bytesReceived > 0 Then ReDim Preserve m_data(bytesTotalReceived + bytesReceived - 1)
11
8619
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling mechanisms. I use a non-blocking approach for this, using the call to 'poll' to support the async mechanism - rather than the 'begin' and 'end' functions. I already found that connecting doesn't set the "isconnected" variable correctly...
1
3519
by: Cramer | last post by:
I'm running XP Pro/SP2 + patches and updates, with Visual Studio Professional 2008 (and no prior installation of Visual Studio ever installed). When attempting to open an ASP.NET Web application project, Visual Studio shuts down immediately and with no error message. I can open Visual Studio - but when subsequently attempting to open the project, Visual Studio immediately shuts down. More specifically:
0
1573
by: =?Utf-8?B?UmFqbmk=?= | last post by:
Dear William Stacey, I have written a server code using the Windows Socket API's. Wherein I have created the socket and bound it to a particular IP address and port number. Later I have made the socket in non-blocking mode by using the proper socket option ( i.e. SO_RCVTIMEO). After which with the use of recv() I am trying to get into the receive mode. Here as the receive time out is being used the socket should come out of the block...
0
9673
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
9522
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
10448
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
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9046
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...
0
6784
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
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...
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.