thank you very much nico,

so here is what i plan to do, in my everlasting socket. hope u'll
correct and make some suggestions

/////////////////////////////////////////
server:
newsock=accept(sock)

while(1){
/* read, say a 4 byte command ,this can be KEEP_ALIVE or SEND  */   
read(newsock,buff, 4)

if(buff==KEEP_ALIVE) /* connection ok , do nothing*/
sleep(30) /* sleep 30 sec */

if(buff==SEND) /* client is sending data */
/* do read() as required
starting seq check or packet length check or ... */

}

//////////////////////////////////////////



but then, a problem rises, when the server is in sleep() the data
arrives at socket. so is the socket is buffered? - i think it is
because the client and server are not in sync - when server does
read(n bytes) it reads n bytes and clears that and the subsequent read
reads the rest. is that so?




--- In [email protected], "Nico Heinze" <[EMAIL PROTECTED]> wrote:
>
> --- In [email protected], "Indika Bandara" <indikabandara19@>
> wrote:
> >
> > thank you guys,
> > 
> > i'll try with the ideas u mentioned,
> > some other questions regarding my situation.
> > 
> > in my client it has to have a socket opened for days.(reason
> > is this host-an embedded device- takes quite lot of time to
> > init the socket so for a real time thing it won't work to
> > init sockets each time)
> 
> In theory a socket can be kept open for weeks if the network doesn't
> produce any dropouts.
> 
> > can a TCP/IP socket do this. i.e. keep the socket conected
> > without hanging up? it has to do the same thing(send files)
> > within the same socket at different times. can it be done?
> 
> I would recommend the same approach that many professional companies
> use: make sure that a keep-alive message packet (this is an IP packet
> with your own data, in other words one of your self-defined messages
> such as the login message and the Send Me Some File message and the
> various acknowledgement messages) is sent over the wire every few
> seconds or at least within a predefined time frame. This will keep the
> connection alive as long as you need it (or until some network device
> happens to drop an IP packet).
> 
> With TCP/IP sockets you always have to be aware of the possibility
> that a connection drops; a keep-alive message every (let's say) 30
> seconds is an appropriate and widely-used way to check whether the
> connection is still alive, but if it breaks, you will have to make
> your code able to re-establish the connection.
> 
> > by sending a starting sequence each time a new file is sent
> > will work?
> 
> Send a request packet every time you need something transferred just
> in order to check that the connection is still alive and, if it's not,
> to re-establish it.
> 
> > anyway, how can i decide a proper starting seq since it
> > should be not in the sending packet? i'm sending a jpeg file.
> 
> It doesn't matter what the starting sequence contains; keep in mind
> that the actual data are never sent in the first packet sent to the
> communication partner, actual data are always sent in the second
> packet only. Re-read my paragraphs about the communication protocol,
> then you will notice that every communication begins with a request
> packet; only if this is acknowledged the actual data packets are sent.
> 
> Regards,
> Nico
>







To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/c-prog/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to