0

When I use CAsyncSocket, can I reuse the same object for another connection (by closing and opening again), or should I create a brand-new object for each connection?

sashoalm
  • 75,001
  • 122
  • 434
  • 781
divB
  • 896
  • 1
  • 11
  • 28
  • Multiple questions are not allowed on this site. Each post is a single question. If you have 3 questions, you make 3 posts. I'll edit your post and delete the other 2 questions. You can make 2 new posts for them. – sashoalm May 10 '14 at 09:45
  • Also, I think your first question can be greatly simplified. Do you agree with my edit? – sashoalm May 10 '14 at 09:47

1 Answers1

0

The socket can be reused but it often takes a couple of minutes before it will work. So you should create a new object for each connection.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
  • Thanks - I am not sure if I really got it yet. So the correct approach is to "CMyConnSock *s = new CMyConnSock(); m_listenSock.Accept(*s);"? It bothers me that Accept() wants to have a reference (rather than a pointer) if it's supposed to be a dynamic object anyway. Furthermore, how is "s" destroyed then? Is it the correct way to overwrite "Close" and insert a "delete this"? – divB May 10 '14 at 17:42