Results 1 to 8 of 8
  1. #1
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Question Serving up a Webpage

    I am trying to create a chat program where, I run a server program on my computer, and anyone who connects to my private IP address via port 4444 will receive a webpage (chat.html). My problem is that no one on my private network can get my chat.html page when they connect to my IP address although they can connect. The chat.html file is located on my machine in the same folder as the server program. What do I have to do to the chat.html file or my server program that will make the other computer capable of receiving the file?

  2. #2
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    5

    Default

    Have you tested opening the file from the server program without sending it.
    Can it be opened?

    If the server is successful opening the file, but not sending it; how do you send it?
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  3. #3
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    I am able to open up the html file, and I haven't been able to send the html file without the other computer have had a client program to connect to it first. I did some research, and it seems that I need to create a servlet that will serve the html file when I connect to it from my browser... My only question is how to create a servlet that will do so (or maybe the file could be downloaded ) and do I need tomcat to test my servlet?

  4. #4
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    5

    Default

    I'm lost on what you are trying to do.

    Is the client a program you have written or any Web browser?
    If not a Web browser; should the file be sent on connection or when requested?
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  5. #5
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    Just any web browser. Once connected the user should be presented with a webpage, just like a web server.

  6. #6
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    5

    Default

    I've never used Java's built-in classes for HTTP, maybe they can be used.

    Otherwise:

    When the client is connecting, it will send the line
    GET (*) HTTP/1.(**)
    ending with \r\n, (*) is the file the client is trying to access: \ for the default page. (**) will be 1, but 0 on Lynx and Mobile Safari (old protocol version).
    After that line the client will also send a number of lines (including virtual host), all ending with \r\n, followed by an empty line ending with \r\n.

    The the server should send:
    HTTP/1.(**) 200 OK\r\n
    Content-Length: (***)\r\n
    Connection: close
    \r\n
    (****)

    Where (***) is the number of bytes, in decimal (10-base), in the file to send,
    and (****) is all bytes in the file to send.
    And then close the connection.



    But the best, and easiest way, might be to just install a HTTP server on your computer.
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  7. #7
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    Thank you for all your help.

    I followed what you said and did a little research and found what I needed to write the contents of my 'chat.html' file to any socket that connects to my java server. But a new problem has surfaced. The webpage also has an <iframe> tag that displays another webpage (An empty html file that the server will write to) but my initial webpage cant find. It attempts to look for it at http://192.168.15.3:15975/text.html.

    Do I need to place my 'text.html' file some where in on my hardrive so that my initial webpage can find it? I've tried send 'chat.html' and 'text.html' but the two website end up right on top of each other and not inside of the <iframe> tag. Where should I go from here.

    If this isn't possible then I might just go with a web server that just sends a client jnlp file and the clients can just use Java web start to run the program. I started with this idea because it was the easiest one todo.

  8. #8
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    5

    Default

    I assume "chat.html" does not define a base catalogue.
    The file for the iframe (src ?) should be "text.html" (or "./text.html"), but I would suggest renaming the file to just "text" or "text.txt" if it is just plain text (MIME: text/plain). It should be located in the same catalogue as "chat.html".

    If you are using to protocol a wrote, the easiest way to avoid an attack where someone tries to access you computes files is to not allow any other file that intended, by having a list of accepted file. But I would suggest to make text.html not an actual file but rather store its content internally in the server program as a StringBuilder and send the StringBuilder's content rather the a file's content.

    Why don't just make an applet and attach it the to a HTML, otherwise you most learn how the receive the messages the clients writes (PUT verb in HTTP).
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

Similar Threads

  1. [HELP] How to run this applet in webpage? [HELP]
    By velianko1 in forum Java Applets
    Replies: 4
    Last Post: 12-16-2010, 06:09 PM
  2. Getting content from a webpage--help!
    By danilson in forum Advanced Java
    Replies: 4
    Last Post: 12-01-2010, 03:19 PM
  3. Cannot Get gif to show on webpage
    By ShinTec in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 09-26-2010, 02:36 PM
  4. Add a Swing UI in a WebPage
    By ivvgangadhar in forum AWT / Swing
    Replies: 9
    Last Post: 06-30-2009, 09:16 AM
  5. save a webpage.....?
    By 05bit044 in forum Networking
    Replies: 1
    Last Post: 08-04-2008, 05:49 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •