|
| 1 | +# HTTP Single File Server |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +*** |
| 6 | + |
| 7 | +I'm happy to share with you my custom server written in Java. |
| 8 | + |
| 9 | +Network programming is very important. Remember that the Internet |
| 10 | +was created for that very reason: that is, computers |
| 11 | +must communicate to one another around the world and |
| 12 | +data must arrive as soon as possible. |
| 13 | + |
| 14 | +Unlike C, in Java you don't need to do much complexity, Java |
| 15 | +does that exactly. But remember, data will always end as bytes. |
| 16 | +So, everything can be processed by a computer as long as the |
| 17 | +programmer can represent the data as bytes. |
| 18 | + |
| 19 | +This custom server only accepts GET request by browsers and |
| 20 | +you can further enhance it by adding implementation for other |
| 21 | +HTTP methods. And since this is a webserver, we want also to have |
| 22 | +port 80, but then again, you can easily change that in the main method. |
| 23 | + |
| 24 | +Remember that both servers and |
| 25 | +browsers can pass data to one another, but typically a browser will always |
| 26 | +initiate the connection while the server is just always waiting for a connection. |
| 27 | +The same is true for other servers like Telnet or FTP servers. |
| 28 | + |
| 29 | +Yet, HTTP is good also to pass any data as long |
| 30 | +as it is expressed in bytes. HTTP is so famous now as it is the protocol of |
| 31 | +web servers and browsers, so more often, we always link HTTP for web sites. |
| 32 | +Also, updated browsers nowadays can display more than text documents like PDF and |
| 33 | +images and even markdown files. |
| 34 | + |
| 35 | +Also, bytes are not even numbers, they are just representation for us humans because |
| 36 | +a computer can only understand the presence or absence of an electrical pulse: that |
| 37 | +is, again, represented as 0 and 1. For today, of course, typical users will hate seeing |
| 38 | +0s and 1s so programmers do the abstraction. |
| 39 | + |
| 40 | +## Q&A |
| 41 | + |
| 42 | +If you have questions, please feel free to ask me: |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +You can also create a pull request to start the discussion or query/ies. |
| 47 | + |
| 48 | +Or, you can raise an issue. I promise I will answer your questions. |
| 49 | + |
| 50 | +## Compiling |
| 51 | + |
| 52 | +This is namespaced as package `xdvrx1_serverProject`. It is up to your IDE |
| 53 | +how it actually manages Java projects. |
| 54 | + |
| 55 | +Once you set this up correctly, the steps are: |
| 56 | +1. Compile the project. |
| 57 | +2. Run the project. |
| 58 | +3. Put `index.html` to your working directory |
| 59 | +and other sample files. |
| 60 | +3. Open a browser. |
| 61 | +4. Type in the address bar `localhost`. |
| 62 | +5. See the default web page! |
| 63 | +6. Access every file in that root directory |
| 64 | +by typing the filename relative to that directory |
| 65 | +or just create a list on the default web page. |
| 66 | +7. If you are quite confused, you can download my release. |
| 67 | + |
| 68 | +Remember also that the `index.html` |
| 69 | +is the default web page, manually coded to do so. You can change that. |
| 70 | + |
| 71 | +Once you created the executable jar file, |
| 72 | +all files within the directory of this executable jar file |
| 73 | +can be accessed through this server. |
| 74 | + |
| 75 | +As my example, in my release the executable jar file must |
| 76 | +have its own folder, then inside that folder is the default page |
| 77 | +`index.html`, then you can create subfolder, in my case, |
| 78 | +`data` and you can put files there to be serve by this webserver. |
| 79 | + |
| 80 | +## Contributing |
| 81 | + |
| 82 | +1. Fork it! |
| 83 | +2. Then, made changes and create a pull request. |
| 84 | +I'm much more willing to collaborate with you! |
| 85 | + |
| 86 | +## License |
| 87 | + |
| 88 | +MIT- the permissive license |
0 commit comments