Having problems with DSWIFI examples!

Post Reply
Mr.Default
Posts: 1
Joined: Fri Dec 06, 2013 5:06 pm

Having problems with DSWIFI examples!

Post by Mr.Default » Fri Dec 06, 2013 5:16 pm

What I am trying to do is get the example GETHTTP to connect to a webpage hosted on my IP address, GETHTTP works on other websites like google etc, however when I type my computer IP address it doesn't get past the connect() function.
Connecting to the webpage hosted by my IP works, localhost on my computer through firefox shows the page, and typing the IP address on another device shows the page, however GETHTTP example doesn't get past the connect function, and the server (which is Java) doesn't get past the accept() function.
Any help would be appreciated !!

GETHTTP is exactly the same as the example, with only the URL parameter being changed to my IP address.
Changed the request_text parameter to:
------------------------------------------------------------
GET / HTTP/1.1
Host: (myIpAddress)
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:23.0) Gecko/20100101 Firefox/23.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Cache-Control: max-age=0
------------------------------------------------------------

Java code for server in case you need to take a look:
------------------------------------------------------------
public class WebServer {
PrintWriter out;
/**
* WebServer constructor.
* @throws IOException
*/
protected void start() throws IOException {
ServerSocket s = null;

System.out.println("Webserver starting up on port 80");
System.out.println("(press ctrl-c to exit)");
try {
// create the main server socket
s = new ServerSocket(80);
} catch (Exception e) {
System.out.println("Error: " + e);
s.close();
}

System.out.println("Waiting for connection");

try {
// wait for a connection
System.out.println("Waiting for accept!");
Socket remote = s.accept();
System.out.println("Accepted");
// remote is now the connected socket
System.out.println("Connection, sending data.");
BufferedReader in = new BufferedReader(new InputStreamReader(
remote.getInputStream()));
out = new PrintWriter(remote.getOutputStream());

// read the data sent. We basically ignore it,
// stop reading once a blank line is hit. This
// blank line signals the end of the client HTTP
// headers.
String str = ".";
while (!str.equals(""))
str = in.readLine();

// Send the response
// Send the headers
sendHeader();
// this blank line signals the end of the headers
out.println("");
// Send the HTML page
out.println("<H1>Welcome to the Ultra Mini-WebServer</H2>");
out.flush();
remote.close();
s.close();
in.close();
} catch (Exception e) {
System.out.println("Error: " + e);
s.close();
}

}

public void sendHeader(){
out.println("HTTP/1.1 200 OK");
out.println("Content-Type: text/html");
out.println("Server: Bot");
out.flush();
}

/**
* Start the application.
*
* @param args
* Command line parameters are not used.
* @throws IOException
*/
public static void main(String args[]) throws IOException {
while(true){
WebServer ws = new WebServer();
ws.start();
}

}
------------------------------------------------------------

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests