Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Sockets and Internet Protocols
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
A Functional Approach to Java: Augmenting Object-Oriented Java Code with Functional Principles
this week in the
Functional programming
forum!
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Liutauras Vilda
Ron McLeod
Jeanne Boyarsky
Paul Clapham
Sheriffs:
Junilu Lacar
Tim Cooke
Saloon Keepers:
Carey Brown
Stephan van Hulst
Tim Holloway
Peter Rooke
Himai Minh
Bartenders:
Piet Souris
Mikalai Zaikin
Forum:
Sockets and Internet Protocols
web server
mj zammit
Ranch Hand
Posts: 49
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi
I built a web server which outputs HTML.
Now when i run it and call for the HTML on Internet Explorer the HTML is viewed, but when i call on Firefox no HTML is outputted...
why is that???
here is the source code:
package myservertrial1;
package myservertrial1; /** * * @author marie-jose */ import java.net.*; import java.io.*; import Proxy.Proxy; public class Main { /** * @param args the command line arguments */ static ServerSocket MainSocket = null; final static int defaultPort = 8080; final static int maxPort = 65536; public static void main(String[] args) { // TODO code application logic here int daemonPort; // Parse command line switch (args.length) { case 0: daemonPort = defaultPort; break; case 1: try { daemonPort = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.out.println("Error: Invalid daemon port"); return; } if (daemonPort > maxPort) { System.out.println("Error: Invalid daemon port"); return; } break; default: System.out.println("Usage: Proxy [daemon port]"); return; } try { //If i wanted to see what host the proxy is on i do the following String setLocalHost = InetAddress.getLocalHost().getHostName(); String tmp = InetAddress.getLocalHost().toString(); String setProxyMachineNameandPort = setLocalHost + ":" + daemonPort; // Create main socket System.out.println("Creating Main Socket..."); MainSocket = new ServerSocket(daemonPort); Socket ClientSocket = MainSocket.accept(); System.out.println("Client socket accepted"); //Creating client socket input, to read what the //client wants BufferedReader in = new BufferedReader(new InputStreamReader( ClientSocket.getInputStream())); String str = "."; while (!str.equals("")) { str = in.readLine(); } System.out.println("read input"); //preparing output stream to send back to client OutputStream out = ClientSocket.getOutputStream(); PrintWriter trial = new PrintWriter(out); String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n"; //reply headers trial.println("HTTP/1.0 200 OK"); trial.println("Content-Type: text/html"); trial.println("Server: Bot"); //HTML page trial.println("docType"); trial.println("<html>"); trial.println("<head>"); trial.println("<title> hello </title>"); trial.println("<H1>Welcome to the Ultra Mini-WebServer</H2>"); trial.println("</head>"); trial.println("</html>"); trial.flush(); System.out.println("output sent"); // Pass request to new proxy thread Proxy thd = new Proxy(ClientSocket); System.out.println("sending client to proxy"); thd.start(); ClientSocket.close(); } catch (Exception e) { } finally { try { MainSocket.close(); } catch (Exception exc) { } } } }
Paul Clapham
Marshal
Posts: 27675
89
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
If you install Live HTTP Headers into your Firefox you will see the headers attached to your response. I don't think you meant to write this header:
trial.println("docType");
Joe Ess
Bartender
Posts: 9626
16
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Look very closely at the
structure of an HTTP response
. You are very close.
[
How To Ask Questions On JavaRanch
]
mj zammit
Ranch Hand
Posts: 49
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
thank you for both your help.
yes there was no need for placing doctype and i also had to arrange the reply header
thanks again
Ernest Friedman-Hill
author and iconoclast
Posts: 24204
44
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
IN particular, the issue was that you didn't have a blank line after the headers, right?
[Jess in Action]
[AskingGoodQuestions]
mj zammit
Ranch Hand
Posts: 49
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Sorry for the late reply
This is the modified reply header
public String formOk(String ContentType,long ContentLength) { contentLength = ContentLength; String out =new String(); out += HTTP_PROTOCOL + " 200 Ok" + CR; out += "Server: " + HTTP_SERVER + CR; out += "MIME-version: 1.0" + CR; if (0 < ContentType.length()) out += "Content-type: " + ContentType + CR; else out += "Content-Type: text/html" + CR; if (0 != contentLength) out += "Content-Length: " + Long.toString(contentLength) + CR; if (0 < lastModified.length()) out +="Last-Modified: " + lastModified + CR; out +=CR; return out; }
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Decompression of strings received from socket connection
Multichat Application
Java Server, PHP client
outputting html content to the server
What's problem with this SSL Socket??
More...