• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

CAsyncSocket object recreation

I want to create listen server socket.
After I accept a socket on it I want to
stop listen , and when the connection is closed I want to relisten.

I wrote the next code but I cannot recreate the socket because it is still in use.

Is there any way to solve this problem exept of deleting the object ?

main()
{
CAsyncSock Listener;
Listener.Create();
Listener.Listen()
Listener.Close()
Listener.Create();
Listener.Listen()
}

0
zona
Asked:
zona
  • 2
1 Solution
 
V_BapatCommented:
After Listener.Close() call Listener.Connect() instead of Listener.Create().

Hope that works.
0
 
V_BapatCommented:
OOPS!!! Forget about the earlier  comment.

I think you have to delete the socket and again create it.
0
 
jhanceCommented:
I think you're mixed up on how listen() works.  It "recycles" itself.  The sequence is:

create()
listen()
accept() -> but accept returns a pointer to a NEW socket that you then talk on.  After you're done with it, close and delete that one.  The original listener keeps listening.  Your accept() call should be in a loop of some kind as more than one connection may come in.  Often, this is a useful place for a multi-threaded design.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now