Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
  #1  
Old September 18th, 2003, 11:27 PM
chuachongchee chuachongchee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 57 chuachongchee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Unhappy Connecection Keep-Alive

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..

Reply With Quote
  #2  
Old September 18th, 2003, 11:27 PM
chuachongchee chuachongchee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 57 chuachongchee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
thanks for any help

greatly appreciate all help...

Reply With Quote
  #3  
Old September 19th, 2003, 12:08 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
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.

Reply With Quote
  #4  
Old September 19th, 2003, 12:09 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
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 !

Reply With Quote
  #5  
Old September 19th, 2003, 01:39 AM
chuachongchee chuachongchee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 57 chuachongchee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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...

Reply With Quote
  #6  
Old September 19th, 2003, 04:26 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
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

Reply With Quote
  #7  
Old September 19th, 2003, 06:50 AM
chuachongchee chuachongchee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 57 chuachongchee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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...

Reply With Quote
  #8  
Old September 20th, 2003, 02:30 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
U can use heartbeat mechanism to implement keep-alive....I think..

Reply With Quote
  #9  
Old September 20th, 2003, 08:10 AM
chuachongchee chuachongchee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 57 chuachongchee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
how does this "heartbeat" mechanism work then???

Reply With Quote
  #10  
Old September 20th, 2003, 11:27 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
HEARTBEAT A test method used on Ethernet networks that assists in gleaning the quality of signals.This is its mechanism...

Reply With Quote
  #11  
Old September 20th, 2003, 11:39 AM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,550 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 4 Weeks 15 h 43 m 35 sec
Reputation Power: 640
I try to avoid socket programming myself You may want to consider a 3rd party socket control, like the free one you can get here

http://www.catalyst.com/products/so...s/socketwrench/

Reply With Quote
  #12  
Old September 20th, 2003, 11:47 AM
chuachongchee chuachongchee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 57 chuachongchee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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.

Reply With Quote
  #13  
Old September 21st, 2003, 01:16 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
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 */
}

Reply With Quote
  #14  
Old September 21st, 2003, 01:17 AM
cleverpig cleverpig is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2003
Posts: 1,152 cleverpig User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via MSN to cleverpig
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 */
}

Reply With Quote
  #15  
Old September 21st, 2003, 06:18 AM
chuachongchee chuachongchee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 57 chuachongchee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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????

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Connecection Keep-Alive


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off