473,738 Members | 3,636 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Blocking socket hangs on Accept

opi
My blocking TCP server hangs in the Accept method when the client
software sometimes gets an error. Are there any ways to stop this
blocking in the Accept method so I dont have to restart the server?

I would rather not use threading or non-blocking sockets.

Using VB.Net 2005.

Jan 10 '07 #1
1 2826
op*@du.se wrote:
My blocking TCP server hangs in the Accept method when the client
software sometimes gets an error.
I don't understand this; a blocking TCP server always "hangs" (more
normally described as "blocks") in Accept until a new client connects.

What do you mean by "when the client software sometimes gets an error" -
how is this causing the hang?
Are there any ways to stop this
blocking in the Accept method so I dont have to restart the server?
You could use the Poll method on the server socket in a loop, and only
call Accept when there really is a client connection pending.
I would rather not use threading or non-blocking sockets.
Your server will only ever be able to handle one connection at a time
then, if by 'non-blocking' you also include the style of polling
sockets, using timeouts etc.

Threading really makes blocking sockets a whole lot easier to work with
(although they don't scale much). And IMHO asynchronous sockets are
easier to work with than the poll / timeout style (though they take a
bit of getting used to). The polling / timeout style can make sense in
game scenarios though, where there are time budgets etc.

-- Barry

--
http://barrkel.blogspot.com/
Jan 10 '07 #2

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

Similar topics

2
3893
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add support for sockets to the system. Thread needs to unblock when: - there is socket ready to be read, or
11
8525
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for my server program written in python it simply hangs.it does not show any error also.I've tried sample programs available .I don understand what the reason is as i am quite new to it. here is teh server side program: ///////////////////////
0
1552
by: Michael Petroni | last post by:
hello *, i have a problem with python 2.2.3 under aix 4.3.3 compiled with gcc version 2.9-aix51-020209 (rpm package from ibm). the following code works fine under all other systems: --- import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
3
10398
by: Logan McKinley | last post by:
I have a C# program that uses blocking sockets and want to allow the user to stop the server. The problem I am having is the socket blocks on -------------------------------------------------------------- listener = new System.Net.Sockets.TcpListener(6254); listener.Start(); //skt is a socket skt =listener.AcceptSocket(); <--- this line blocks -------------------------------------------------------------- I attempt to stop the thread...
7
17409
by: Michi Henning | last post by:
Hi, I'm using a non-blocking connect to connect to a server. Works fine -- the server gets and accepts the connection. However, once the connection is established, I cannot retrieve either the local or the remote endpoint from the client-side socket. The *really* strange thing is that Socket.LocalEndPoint is null. According to the doc, that's impossible: reading the LocalEndPoint
11
1873
by: Michi Henning | last post by:
Hi, I'm using a blocking Select() call on a socket with a timeout value of -1. I'd expect the call to block indefinitely, but it doesn't. When I use Poll() instead, a timeout of -1 works fine and blocks indefinitely. The net effect is that I cannot write a select on more than one file descripter if I want to block. (With timeout values >= 0, both Select() and Poll() work fine.)
0
4287
by: chsalvia | last post by:
On Linux (Ubuntu) I'm trying to figure out how to avoid recv() calls that hang forever by using using a non-blocking socket along with the select() function. This seems to be the standard way to avoid recv() calls that hang forever. I'm having difficulty getting this to work however. It seems to work sometimes, but occasionally the recv() call hangs. Additionally, I think the loop I'm using is not doing something right, because it slows...
0
1401
by: Blog the Haggis | last post by:
Hi all, I've written a program which distributes binary data to a number of clients via TCP. The program runs perfectly unless one of the client programs hangs and then it freezes while waiting for the socket.send(Data) method to complete. I've tried all of these socket options to overcome this event: 'Set send timeout to 2 seconds:
3
8425
by: mp | last post by:
Code is at bottom. Basically, if I turn off socket blocking prior to connecting, I get a "Socket is not connected" error when I try to send data. However, if I do not turn off blocking, OR if I place a print statement anywhere before the send call, it works! WTF? I'd like to understand what's going on in the background here, if you know don't skimp on the details. Thanks
0
9476
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
9335
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...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
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
8210
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
6751
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
6053
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();...
1
3279
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
2745
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.