Re: Connection close in HTTP server



Well, you were told (by the zero return value) that the connection
is closed, so you are supposed to close your end of the socket.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

"Nuno Magalhaes" <nunommagalhaes@xxxxxxxxxxx> wrote in message
news:1133584545.213275.316780@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>I don't get it. My Receive function doesn't block and doesn't throw
> exceptions when there is no more to read, it just keeps returning 0
> over and over when it reaches the end. Do you know why? (only a Send
> will throw an exception)
> (take a look at the code below)
>
> while(true)
> {
> try
> {
> int
> j=socket.Receive(bytes,receivedOffset,socket.Available,SocketFlags.None);
> receivedOffset+=j;
> }
> catch(Exception)
> {
> break;
> }
> }
>
>
> Alexander Nickolov wrote:
>> Very simple - don't Send. Receive will tell you when the
>> connection is closed.
>>
>> --
>> =====================================
>> Alexander Nickolov
>> Microsoft MVP [VC], MCSD
>> email: agnickolov@xxxxxxxx
>> MVP VC FAQ: http://www.mvps.org/vcfaq
>> =====================================
>>
>> "Nuno Magalhaes" <nunommagalhaes@xxxxxxxxxxx> wrote in message
>> news:1133534266.092059.131860@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>> > How do I get all the data from the server if in the last chunk the
>> > server closes the connection?
>> > I'm doing a loop that consists on a:
>> > Socket.Receive
>> > Socket.Send
>> > The Send function is to check if the socket is alive and the receive
>> > function receives the data at specified offsets. If the data arrives
>> > between Receive and Send functions and the connection is closed by the
>> > server (as described in the HTTP RFC) I can't get the last bytes of the
>> > html page anymore (because the socket gets dead with the send
>> > function).
>> >
>> > Does anyone knows a solution for this problem? Someone must have
>> > implemented a simple HTTP browser from the "ashes"...
>> >
>> > Thanks in advance,
>> > Nuno Magalhaes.
>> >
>


.



Relevant Pages

  • Re: Socket Exception
    ... In this case the server most likely rejected your ... connection. ... Each command is a new socket connection that is opened and closed ... /// Required designer variable. ...
    (microsoft.public.win32.programmer.networks)
  • Re: ASP.NET 2.0 - a newbie question
    ... Is there some experienced ASP.NET 2.0 developer, ... server that comes bundled Microsoft VWDE. ... A connection attempt failed because the ... connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& ...
    (microsoft.public.dotnet.framework.aspnet)
  • error when move web service from dev machine to test server
    ... I have a simple web service that I developed on my laptop that resides ... test server, & when I try to run it, I get the error "No connection could be ... No connection could be made because the target machine actively refused it ... Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Messaging alert
    ... I was hopping that I could use sockets to create a connection back and forth in order to send the message. ... I want to be able to send a file name and other information thru the client socket to then process in the servers. ... fileevent $sock w ... At the server side I am listening at the port and execute Accept2 when the socket is created. ...
    (comp.lang.tcl)
  • Re: Strange server socket behaviour
    ... asynchronous server socket: ... I already have a perfectly working server that uses asynchronous sockets ... Why should the remote client close the connection? ... when a .NET client connects. ...
    (microsoft.public.dotnet.framework)