Persistent socket connection
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rakesh_Sharma
Posted On:   Sunday, May 18, 2003 01:31 AM

i created an http server that would serve the html page requested by the browser. i want to create a persistent connection with the web browser so that the browser dont have to again and again open a connection to get every resource on the page. for this i am trying to send "Connection: Keep-Alive" header to the client but despite this the browser closes connection after every resource and opens a new one for the next resource. this is the code snippet that i m using /*Whenever a client connects he is sent to this run method*/ public void run() { boolean Persistant=true; while (Persistant) { ArrangeRequest(); // Read the request from the    More>>

i created an http server that would serve the html page requested by the browser. i want to create a persistent connection with the web browser so that the browser dont have to again and again open a connection to get every resource on the page. for this i am trying to send "Connection: Keep-Alive" header to the client but despite this the browser closes connection after every resource and opens a new one for the next resource.



this is the code snippet that i m using



/*Whenever a client connects he is sent to this run method*/
public void run()

{

boolean Persistant=true;

while (Persistant)

{

ArrangeRequest(); // Read the request from the client

if (!CheckPersistant()) // Check for persistency

Persistant = false; //Do not need to continue

SendResource();//Sends the resource asked with appropriate headers

}

}//run




public boolean CheckPersistant()

{

int i=0;

while ( i < 7) { // Check whether the browser sends Keep-Alive or not

if (InStream[i].startsWith("Connection: Keep-Alive"))//InStream is the array of headers send by the client containing 7 elements

{ return true; //Need Persistent connection

}

i++;}

return false; //Does not need

}


Whats wrong with it?

   <<Less

Re: Persistent socket connection

Posted By:   Christopher_Koenigsberg  
Posted On:   Sunday, May 18, 2003 05:22 PM

I suspect (?) you might have to write your own browser... unless you find one that does honor this Keep-Alive directive with Http 1.1. Maybe try the w3c's "Amaya" browser?

About | Sitemap | Contact