Created
February 7, 2022 15:05
-
-
Save sakshamgurung/70edb960879d1462dc5f90d92ec1f1db to your computer and use it in GitHub Desktop.
Connection class part I
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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