By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,885 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,885 IT Pros & Developers. It's quick & easy.

Socket Listen for single connection

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.