473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Socket Listen for single connection

I am writing an application that simulates a TCP device that only
accepts one connection at a time. For my application, I would like
connection requests to fail if one already exists. So far I have the
following code:

IPAddress ip = Dns.Resolve("localhost").AddressList[0];
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint ep = new IPEndPoint(ip, 2323);
s.Bind(ep);
s.Listen(0);

while(true)
{
Socket s1 = s.Accept();
s1.Receive(request);
....
s1.Close();
}

It seems that Listen(0) does not work as expected. If I open a client
to this application and leave it idle, and then open up a second
client, it waits for the first client to finish. If I open a third
client, the conneciton fails as I would like it to. It seems to me that
Listen(0) is behaving as I expect Listen(1) should.

How can I prevent the second from waiting? I want it to fail
immediately. Any suggestions?

Thanks.

Mar 31 '06 #1
1 1392
Hello, Yofnik!

Read my answer to your question on microsoft.public.dotnet.framework

( http://groups.google.com.ua/group/mi...3f59d84ce694db )

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Apr 1 '06 #2

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

Similar topics

3
by: ferbar | last post by:
Hello all, This may sound pretty basic stuff.. but I'm working on a socket example whose client seems to work fine, but the server doesn't send to the client the expected result. The problem is...
2
by: Lenard Gunda | last post by:
Hi, I have the following problem when I am working with sockets in C#. I do not remember running into the same problem some while ago, when working with sockets from C++ (using native code, not...
2
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless...
4
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket...
6
by: Sean | last post by:
Hi Everyone, My apologies for a somewhat dump question but I am really stuck. I have been working on this code for two days straight I am dont know what is wrong with it. when I run the code, All...
2
by: darthghandi | last post by:
I am trying to pass a socket object when an event is signaled. I have successfully bound to a network interface and listened on a port for incoming connection. I have also been able to accept...
5
by: darthghandi | last post by:
I've created a class to listen to all interfaces and do a BeginAccept(). Once it gets a connection, it passes the connected socket off and stores it in a List. Next, it continues to listen for...
0
by: mhetfield | last post by:
Hi, I'm writing a client-server socket program. the client will be an instance of the well-known telnet application. i want to implement a simple authentication between the server and the client. ...
7
by: silverburgh.meryl | last post by:
Hi, I read the following code which open a server socket for client request. However, i would like to know how can I change it so that i just listen for client requestfor 10 seconds, after...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.