|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I currently have a chat server...
clients connect to this server and the server simply broadcasts the msg to all clients... HOW do i do a "keep-Alive" system?? similar to IRC chat.... the server sends out a message... e.g "PING" (same as irc) if the clients responds with a "PONG" .. the connection is kept open... if not, after X time, the connection will be forcefully closed by the server.. |
|
#2
|
|||
|
|||
|
thanks for any help
greatly appreciate all help...
|
|
#3
|
|||
|
|||
|
HTTP Keep Alive
Http Keep-Alive seems to be massively misunderstood. Here's a short description of how it works, under both 1.0 and 1.1, with some added information about how Java handles it. Http operates on what is called a request-response paradigm. This means that a _client_ generates a request for information, and passes it to the server, which answers it. In the original implementation of HTTP, each request created a new socket connection to the server, sent the request, then read from that connection to get the response. This approach had one big advantage - it was simple. Simple to describe, simple to understand, and simple to code. It also had one big disadvantage - it was slow. So, keep-alive connections were invented for HTTP. |
|
#4
|
|||
|
|||
|
HTTP/1.0
Under HTTP 1.0, there is no official specification for how keepalive operates. It was, in essence, tacked on to an existing protocol. If the browser supports keep-alive, it adds an additional header to the request: Connection: Keep-Alive Then, when the server receives this request and generates a response, it also adds a header to the response: Connection: Keep-Alive Following this, the connection is NOT dropped, but is instead kept open. When the client sends another request, it uses the same connection. This will continue until either the client or the server decides that the conversation is over, and one of them drops the connection. HTTP/1.1 Under HTTP 1.1, the official keepalive method is different. All connections are kept alive, unless stated otherwise with the following header: Connection: close The Connection: Keep-Alive header no longer has any meaning because of this. Additionally, an optional Keep-Alive: header is described, but is so underspecified as to be meaningless. Avoid it. ![]()
__________________
Being a Code Headman !
|
|
#5
|
|||
|
|||
|
i guess.... u mis-understood what i am trying to say...
i have said in the above msg that this is for a vb chat program... this has nothing to do with http 1.0/1.1 header...... what i am using is Winsock chat on TCP Protocol... |
|
#6
|
|||
|
|||
|
Oh!"Keep-Alive" is the special of tcp..U can find it in RFC1122...
This is the some kownledge: TCP Keep-Alives Implementors MAY include "keep-alives" in their TCP implementations, although this practice is not universally accepted. If keep-alives are included, the application MUST be able to turn them on or off for each TCP connection, and they MUST default to off. Keep-alive packets MUST only be sent when no data or acknowledgement packets have been received for the connection within an interval. This interval MUST be configurable and MUST default to no less than two hours. It is extremely important to remember that ACK segments that contain no data are not reliably transmitted by TCP. Consequently, if a keep-alive mechanism is implemented it MUST NOT interpret failure to respond to any specific probe as a dead connection. An implementation SHOULD send a keep-alive segment with no data; however, it MAY be configurable to send a keep-alive segment containing one garbage octet, for compatibility with erroneous TCP implementations. http://www.freesoft.org/CIE/RFC/1122/114.htm |
|
#7
|
|||
|
|||
|
still....
it doesnt explain in detail how this is to be done.... i do not need the background knowledge on TCP, for as i am an networking student, CCNA too... what i need is how this is to be implemented... |
|
#8
|
|||
|
|||
|
U can use heartbeat mechanism to implement keep-alive....I think..
|
|
#9
|
|||
|
|||
|
how does this "heartbeat" mechanism work then???
|
|
#10
|
|||
|
|||
|
HEARTBEAT A test method used on Ethernet networks that assists in gleaning the quality of signals.This is its mechanism...
|
|
#11
|
|||
|
|||
|
I try to avoid socket programming myself
You may want to consider a 3rd party socket control, like the free one you can get herehttp://www.catalyst.com/products/so...s/socketwrench/ |
|
#12
|
|||
|
|||
|
i know winsock is not really good
but i need this app to work without installing any new app ...
and i need this app to work on all platforms.... any other ideas on how to achieve this on winsock??? and i need some sample code on this as well... all help greatly appreciated.... ![]() Last edited by chuachongchee : September 20th, 2003 at 11:55 AM. |
|
#13
|
|||
|
|||
|
U can implement it with tcp kepp-alive mechanism by youslef..I had ever done it with gnu c...This is my source code!..Hope it is hopeful!Good luck!
Heartbeat_Client.c: #include "unp.h" static int servfd; static int nsec; /* #seconds betweeen each alarm */ static int maxnprobes; /* #probes w/no response before quit */ static int nprobes; /* #probes since last server response */ static void sig_urg(int), sig_alrm(int); void heartbeat_cli(int servfd_arg, int nsec_arg, int maxnprobes_arg) { servfd = servfd_arg; /* set globals for signal handlers */ if ( (nsec = nsec_arg) < 1) nsec = 1; if ( (maxnprobes = maxnprobes_arg) < nsec) maxnprobes = nsec; nprobes = 0; Signal(SIGURG, sig_urg); Fcntl(servfd, F_SETOWN, getpid()); Signal(SIGALRM, sig_alrm); alarm(nsec); } static void sig_urg(int signo) { int n; char c; if ( (n = recv(servfd, &c, 1, MSG_OOB)) < 0) { if (errno != EWOULDBLOCK) err_sys("recv error"); } nprobes = 0; /* reset counter */ return; /* may interrupt client code */ } static void sig_alrm(int signo) { if (++nprobes > maxnprobes) { fprintf(stderr, "server is unreachable\n"); exit(0); } Send(servfd, "1", 1, MSG_OOB); alarm(nsec); return; /* may interrupt client code */ } |
|
#14
|
|||
|
|||
|
Heartbeat_Server.c:
#include "unp.h" static int servfd; static int nsec; /* #seconds between each alarm */ static int maxnalarms; /* #alarms w/no client probe before quit */ static int nprobes; /* #alarms since last client probe */ static void sig_urg(int), sig_alrm(int); void heartbeat_serv(int servfd_arg, int nsec_arg, int maxnalarms_arg) { servfd = servfd_arg; /* set globals for signal handlers */ if ( (nsec = nsec_arg) < 1) nsec = 1; if ( (maxnalarms = maxnalarms_arg) < nsec) maxnalarms = nsec; Signal(SIGURG, sig_urg); Fcntl(servfd, F_SETOWN, getpid()); Signal(SIGALRM, sig_alrm); alarm(nsec); } static void sig_urg(int signo) { int n; char c; if ( (n = recv(servfd, &c, 1, MSG_OOB)) < 0) { if (errno != EWOULDBLOCK) err_sys("recv error"); } Send(servfd, &c, 1, MSG_OOB); /* echo back out-of-band byte */ nprobes = 0; /* reset counter */ return; /* may interrupt server code */ } static void sig_alrm(int signo) { if (++nprobes > maxnalarms) { printf("no probes from client\n"); exit(0); } alarm(nsec); return; /* may interrupt server code */ } |
|
#15
|
|||
|
|||
|
please read properly
1st: u was not answering this qns of mine but going all the way to some unknown place...
next: this is a VB forum, mister.... so i think your source code is not of any help..... i need actual, workable, source code in VB.... anyone else has any brillant ideas???? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Connecection Keep-Alive |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|