Skip to content

Instantly share code, notes, and snippets.

sakshamgurung / airports.json
Created May 21, 2023 13:16
Some dummy data on airports in Japan
"code": "AKJ",
"lat": "43.665",
"lon": "142.453",
"name": "Asahikawa Airport",
"city": "Asahikawa-shi",
"state": "Hokkaido Prefecture",
"country": "Japan",
"woeid": "28360516",
sakshamgurung /
Created February 7, 2022 15:06
Connection class part III
// continue Connection class...
// helper method: getting the path to access the requested resource/information hosted by the server (aka routing)
private static Path getFilePath(String path) {
Matcher match = Pattern.compile("/watch/").matcher(path);
// replacing "watch" with "resources" because we have our videos inside that directory
path = path.replaceAll("/watch/", "./");
path = path + ".mp4";
return Paths.get(path);
sakshamgurung /
Created February 7, 2022 15:06
Connection class part II
// continue Connection class...
// overiding run method from Thread class
public void run(){
// Initializing a Scanner class to read stream input from the
// socket connection between server and client
Scanner scan = new Scanner(, "UTF-8");
// separating the HTTP request header from rest of the HTTP message
// "\\r\\n\\r\\n" below refers to the 'empty line' from fig.1
sakshamgurung /
Created February 7, 2022 15:05
Connection class part I
// Inside file
// Thread class is extended to use multi-threading facility
class Connection extends Thread {
DataInputStream in;
DataOutputStream out;
Socket clientSocket;
public Connection (Socket clientSocket) {
try {
this.clientSocket = clientSocket;
sakshamgurung /
Created February 7, 2022 15:03
Webserver class
// Inside file
public class WebServer{
public static void main (String args[]) throws IOException NoSuchAlgorithmException {
int serverPort = 9090;
// allocating resources for server's socket and assigning a port number
ServerSocket listenSocket = new ServerSocket(serverPort);
System.out.println("Server program started...");
while(true) {
// listening to the assigned port number and accepting
sakshamgurung /
Created February 7, 2022 15:02
Imports for
// Inside file
// Some necessary imports
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
<!-- ./public/cats.html -->
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Cat Paws</title>
<h1 style="text-align: center;">Cat-videos</h1>
<div style="display: flex; justify-content: center;">
<!-- ./public/index.html -->
<!DOCTYPE html>
<meta charset="UTF-8">
<title>Cat Paws</title>
<h1 style="text-align: center;">Cat Paws</h1>
# staff.feature
# this is a background keyword learn more here:
Given a company has been created with following information and default attributes
# this is a data table you can learn more from:
| email | |
| mobileNo | 9816564565 |
| password | password |
And super admin has accepted the company
And company has logged in with email "" and password "" using the webUI