Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Re: html browser

Hi,

What I meant by HTTP server is nothing complex as Flash XML socket
server or Web Matrix server. It's just a TCP socket connection providing
HTTP header+ document. 

If u want to render your XML with XSL u can either 
do the XSLT transformation before sending the document via socket and
send the HTML document directly or 
u can add XML style sheet header on top of the XML document so the
browser will take care of the XSLT.

Steps:
1) Accept the connections on specific port and invoke new thread to
handle the request(better do this in a separate thread)

while (true) {
	try {
		ServerSocket serverSocket = new ServerSocket(PORT,5);
		//Waiting for a connection ...
		Socket newConnection = serverSocket.accept();
		//connection recieved
		//here u can set comnnection timeout counter[optional]
		
		//start new thread to handle the connection.
		//in side this u can check for the request url and take
actions 		//accordingly.
		Connectionhandler connectionhandler = new
Connectionhandler (newConnection);
		connectionhandler.start();

		//close the server socket
		serverSocket.close();
	} catch (IOException e) {
		//handle the eror
	}
}


2) u can handle the request in the "Connectionhandler" class. 
U can read the request
DataInputStream in = new DataInputStream(
	new BufferedInputStream(newConnection.getInputStream()));

and with a simple string manipulation extract the request url
and act accordingly to create the response stream(your document to be
output).

3) send the response
DataOutputStream out = new DataOutputStream(
	newConnection.getOutputStream()); 
out.writeBytes(output);	

4) u can send the out put stream directly with out adding any HTTP
header. This does work with out giving any trouble with Internet
Explorer. But due to no HTTP header IE will assume its default
properties. So u have less control in cases such as browser caching. 
Here u have two options
Either u can attach the HTTP header on top of your response.
Or add meta-tags on to your html page like shown below.
<head>
<META http-equiv="Content-Type"
content="text/html;charset=windows-1252"/>
<META http-equiv="Cache-control" content="no-store, no-cache,
must-revalidate;charset=windows-1252"/>  

These can be included in your XSL if u r doing XSLT.

Hope this will help u
Hasith






Back to the top