Skip to content

Instantly share code, notes, and snippets.

@sakshamgurung
Created February 7, 2022 15:05
Show Gist options
  • Save sakshamgurung/70edb960879d1462dc5f90d92ec1f1db to your computer and use it in GitHub Desktop.
Save sakshamgurung/70edb960879d1462dc5f90d92ec1f1db to your computer and use it in GitHub Desktop.
Connection class part I
// Inside WebServer.java 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;
// accessing input stream from the given socket
this.in = new DataInputStream( this.clientSocket.getInputStream());
// accessing output stream from the given socket
this.out = new DataOutputStream( this.clientSocket.getOutputStream());
// starts a new thread
this.start();
} catch(IOException e) {
System.out.println("Connection: "+e.getMessage());
}
}
// continue...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment