473,406 Members | 2,371 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,406 software developers and data experts.

Is it OK to close listenSocket after accept?

Ole
When creating a socket connection a typical scenario is:
MySocket = ListenSocket.Accept();

but if only one connection is necessary will it then not be better to close
the ListenSocket after that line?

Thanks
Ole
Aug 22 '06 #1
3 2032
Hello, Ole!

Obut if only one connection is necessary will it then not be better to
Oclose the ListenSocket after that line?

Well, you can close listening socket after receiving one connection.
Nothing bad will happen.

Another option is not calling Socket.Accept(...);

The latter is more flexible, because if you loose that one connection
you can accept another one. And you will not have to do all the bindings again
( Socket.Bind() , Socket.Listen(... ) )

Also the latter option is more secure. Imagine the situation when you've received a connection,
and closed listening socket. In the mean time another application ( malware etc ) binds on the
same address and: a) intercept your clients b)introduce denial-of-service attack

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Aug 22 '06 #2
Ole
What should I do instead of calling Socket.Accept to make a connection?

Thanks
Ole

"Vadym Stetsyak" <va*****@ukr.netwrote in message
news:uu****************@TK2MSFTNGP04.phx.gbl...
Hello, Ole!

Obut if only one connection is necessary will it then not be better to
Oclose the ListenSocket after that line?

Well, you can close listening socket after receiving one connection.
Nothing bad will happen.

Another option is not calling Socket.Accept(...);

The latter is more flexible, because if you loose that one connection
you can accept another one. And you will not have to do all the bindings
again
( Socket.Bind() , Socket.Listen(... ) )

Also the latter option is more secure. Imagine the situation when you've
received a connection,
and closed listening socket. In the mean time another application (
malware etc ) binds on the
same address and: a) intercept your clients b)introduce denial-of-service
attack

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Aug 22 '06 #3
Hello, Ole!

To make a connection ( to connect ) on some host you can use
Socket.Connect(...) method.
To accept connection from another host you use Socket.Accept(...).

Its by design

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Aug 22 '06 #4

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

Similar topics

0
by: Daniel T. | last post by:
The code below fails. Socket.accept blocks inside the thread and doesn't let go, even after the socket was closed. From the error presented, the socket never actually closes. I realize that the...
9
by: Pack Fan | last post by:
I've noticed that session variables will persist on Mac IE even after all browser windows have been closed. One must quit the program to clear the session variables. This presents a security risk...
4
by: trinity | last post by:
I am wondering if it is possible to accept and close the active window using its handle. I already have the handle using getActiveWindow(). I need to be able to click on the "yes" button to...
4
by: rs | last post by:
how I the client tell the server that the socket is closed? or this there an even that informs the server that the clients socket is close? Oh, I am using vb.net 2003 Thanks
4
by: stevong | last post by:
It works on Konquerer though. I remember it works on IE too. I've tried window.close() too. Doesn't work on Firefox also. I've also tried to create a function. It doesnt work on Firefox also....
5
by: freelancex | last post by:
Hi, Im new to this forum, and new to scripting in general. Im an ICT Technician for a high school and i am designing a Form in visual basic 2005. The intended purpose of the Form, is to prevent...
15
by: Andyza | last post by:
I'm looking at another developers code and I'm now confused about the correct way to close a database connection and destroy the object. I would normally do it this way: Set conn =...
0
by: Zeez82 | last post by:
I have a WCF application where serveral clients connect to a server. I'm totally aware of the fact that I should always call the 'Proxy.Close()' method everytime the client quits to free some IIS...
0
by: meLlamanJefe | last post by:
I have the following code snippet that is used in a simple multi-threaded server program I am testing. The ServerSocket class binds to a port and creates a listening socket. Then it sits and waits...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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,...
0
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...
0
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...
0
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...
0
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...

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.