Re: closing ASyncSocket



Okay thanks. I'm going to give that a try next. I'm not sure from your
response about the answer to some of my detailed questions. So I will repeat
those.

Would ShutDown be blocking under this situation and if not would I get a
notification when it is finished and what would this notification be?

Is it permitted to call Close() from either side and will the opposite side
always get the OnClose() call?

I reread the help for the ShutDown() call. It says "Note that ShutDown does
not close the socket, and resources attached to the socket will not be freed
until Close is called. An application should not rely on being able to reuse
a socket after it has been shut down. In particular, a Windows Sockets
implementation is not required to support the use of Connect on such a
socket.".

This leads me to believe ShutDown() is not the solution to my problem. It
sounds like I can't Connect, Send, Close and then expect to be able to
Connect again to the same or a different socket. Is this correct?

I have done some further tests and run into a more fundamental problem. I
separated the Connect, Send and Close sequences into three separate buttons.
The Connect buttonwill connect and then at OnConnect, enable the Send
button. The Send first disables itself, then sends four blocks of data, then
on the next OnSend, reenables the button. The Close button Close()s then
disables the Send button. Ok. I can connect. I can send the first batch of
four blocks. I never press close. When I try to Send again, the first block
is sent but it is never received. For the purpose of debugging, I changed
the number of blocks sent to two and six. In each case, all could be sent
the first time and the second time there is a failure to send or be
received. I checked with breakpoints that Close() is never being called.
What could it be? Is there a timeout after sedning in which a socket closes
itself or shuts itself down or something?

Thanks...



"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:poi3129irc124j9bn6v2vu4fuis7tminpu@xxxxxxxxxx
Yes, that's the point of what I said. If you don't call ShutDown, there
is no obligation
on the part of any particular WinSock implementation to flush the pending
buffers.
joe

On Fri, 10 Mar 2006 13:35:39 +0800, "Bill Brehm" <<don't want any spam>>
wrote:

Joe,

What if I want to Close() the connection to return resources. Should I
call
ShutDown() first to flush the send then call Close() to close? Would
ShutDown be blocking under this situation and if not would I get a
notification when it is finished? Is it permitted to call Close() from
either side and will the opposite side always get the OnClose() call?

Thanks

"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message
news:jmdu0296m5rr1apf770c632ep0psbkqu84@xxxxxxxxxx
If you want to guarantee that everything is sent, call the ShutDown
method
(note the
uppercase "D"). Its argument is whatever operations you want to shut
down, and although
it doesn't give the name of a type, the documentation says that 0 to
shut
down receives, 1
to shut down sends, and 2 to shut down both. This guarantees that
pending
Send operations
will be flushed out. Close is not required to make sure that pending
data
is sent.
joe

On Wed, 8 Mar 2006 18:52:48 +0800, "Bill Brehm" <<don't want any spam>>
wrote:

I had asked part of this in another thread but i have more related
questions
so I repeat one part.

1. When is it safe after sending to call Close()? I have it implemented
now
where I close from within the OnSend() call when I have no further data
to
send. I thought that means the data is safely underway. But it seems
that
sometimes the data is received on the other side and sometimes it isn't.
I'm
not sure if the connection being closed before the other side reads the
data
out is the cause of the problem or if I maybe have another problem.

2. Then because of that problem, I decided to try Close()ing on the
receiving side (Server) after I received the last data. This was an
improvement because the data was always received. But it seems the
sending
side (Client) doesn't realize the connection is closed. It does get the
OnClose() call. But when I try to initiate another transaction by having
the
client connect to the server, it gets an error that it is already
connected
(10056). Do I need to call Close() from within the OnClose() call
triggered
by the other side?

I'm sure i'll have more later. Thanks...

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm


.



Relevant Pages

  • RE: Does Socket.Shutdown or Socket.Close Block and when?
    ... receive a heartbeat message every 5 seconds on each socket (to make sure the ... connection is still up to each client). ... heartbeat within say 10 seconds then the server will proceed to shutdown the ... the send buffer is empty or becomes empty before the elapsed timeout. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Does Socket.Shutdown or Socket.Close Block and when?
    ... keeps trying to send the data in the send buffers of the socket until TCP ... in the send buffer has been sent or the timeout has elapsed. ... > connection is still up to each client). ... > heartbeat within say 10 seconds then the server will proceed to shutdown the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Code run from IDLE but not via double-clicking on its *.py
    ... I'd definitely wait for the client connection to come in, ... If the remote side shuts down writing, the socket ... you should send the shutdown ...
    (comp.lang.python)
  • Re: Handling multiple connections
    ... each time select says the socket has more data. ... All data being sent by clients are prepended with a header that indicates ... received and thus delays receiving on the other readable sockets. ... When the client closes the connection, ...
    (microsoft.public.win32.programmer.networks)
  • Re: closing ASyncSocket
    ... What if I want to Closethe connection to return resources. ... ShutDown() first to flush the send then call Closeto close? ... receiving side after I received the last data. ...
    (microsoft.public.vc.mfc)