SlideShare a Scribd company logo
Introduction The Server The Echo Client References
REMOTE COMMAND EXECUTION
Muhammad Adil Raja
Roaming Researchers, R .
November 18, 2015
Introduction The Server The Echo Client References
OUTLINE
1 INTRODUCTION
2 THE SERVER
3 THE ECHO CLIENT
4 REFERENCES
Introduction The Server The Echo Client References
OUTLINE
1 INTRODUCTION
2 THE SERVER
3 THE ECHO CLIENT
4 REFERENCES
Introduction The Server The Echo Client References
OUTLINE
1 INTRODUCTION
2 THE SERVER
3 THE ECHO CLIENT
4 REFERENCES
Introduction The Server The Echo Client References
OUTLINE
1 INTRODUCTION
2 THE SERVER
3 THE ECHO CLIENT
4 REFERENCES
Introduction The Server The Echo Client References
INTRODUCTION
Introduction The Server The Echo Client References
THE SERVER I
/∗
∗ Copyright ( c ) 2013, Oracle and / or i t s a f f i l i a t e s . A l l r i g h t s reserved .
∗
∗ R e d i s t r i b u t i o n and use in source and binary forms , with or without
∗ modification , are permitted provided that the f o l l o w i n g conditions
∗ are met :
∗
∗ − Redistributions of source code must r e t a i n the above copyright
∗ notice , t h i s l i s t of conditions and the f o l l o w i n g disclaimer .
∗
∗ − Redistributions in binary form must reproduce the above copyright
∗ notice , t h i s l i s t of conditions and the f o l l o w i n g disclaimer in the
∗ documentation and / or other materials provided with the d i s t r i b u t i o n .
∗
∗ − Neither the name of Oracle or the names of i t s
∗ c o n t r i b u t o r s may be used to endorse or promote products derived
∗ from t h i s software without s p e c i f i c p r i o r w r i t t e n permission .
∗
∗ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
∗ IS " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
∗ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
∗ PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR
∗ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT , INCIDENTAL , SPECIAL ,
∗ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
∗ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
∗ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
∗ LIABILITY , WHETHER IN CONTRACT, STRICT LIABILITY , OR TORT (INCLUDING
∗ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
∗ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Introduction The Server The Echo Client References
THE SERVER II
∗/
import java . net . ∗ ;
import java . io . ∗ ;
public class TelnetServer {
public static void main ( String [ ] args ) throws IOException {
i f ( args . length != 1) {
System . err . p r i n t l n ( "Usage : java EchoServer <port number>" ) ;
System . e x i t ( 1 ) ;
}
int portNumber = Integer . parseInt ( args [ 0 ] ) ;
try (
ServerSocket serverSocket =
new ServerSocket ( Integer . parseInt ( args [ 0 ] ) ) ;
Socket clientSocket = serverSocket . accept ( ) ;
P r i n t W r i t e r out =
new P r i n t W r i t e r ( clientSocket . getOutputStream ( ) , true ) ;
BufferedReader in = new BufferedReader (
new InputStreamReader ( clientSocket . getInputStream ( ) ) ) ;
) {
String inputLine ;
String n u l l S t r =null ;
while ( ( inputLine = in . readLine ( ) ) != null ) {
ProcessBuilder processB=new ProcessBuilder ( " bash " , "−c " , inputLine ) ;
processB . redirectErrorStream ( true ) ;
Introduction The Server The Echo Client References
THE SERVER III
Process process = processB . s t a r t ( ) ;
BufferedReader br = new BufferedReader (
new InputStreamReader ( process . getInputStream ( ) ) ) ;
/ / BufferedReader errorReader = new BufferedReader (
/ / new InputStreamReader ( process . getErrorStream ( ) ) ) ;
while ( ( inputLine=br . readLine ( ) ) ! = null ) {
out . p r i n t l n ( inputLine ) ;
System . out . p r i n t l n ( " Log : "+ inputLine ) ;
}
out . p r i n t l n ( " bye " ) ;
out . flush ( ) ;
System . out . p r i n t l n ( "Bye Input ! " ) ;
System . out . p r i n t l n ( "Bye Error ! " ) ;
br . close ( ) ;
process . destroy ( ) ;
/ / out . p r i n t l n ( " Bye : " ) ;
}
} catch ( IOException e ) {
System . out . p r i n t l n ( " Exception caught when t r y i n g to l i s t e n on port "
+ portNumber + " or l i s t e n i n g f o r a connection " ) ;
System . out . p r i n t l n ( e . getMessage ( ) ) ;
}
}
}
Introduction The Server The Echo Client References
THE CLIENT I
/∗
∗ Copyright ( c ) 1995, 2013, Oracle and / or i t s a f f i l i a t e s . A l l r i g h t s reserved .
∗
∗ R e d i s t r i b u t i o n and use in source and binary forms , with or without
∗ modification , are permitted provided that the f o l l o w i n g conditions
∗ are met :
∗
∗ − Redistributions of source code must r e t a i n the above copyright
∗ notice , t h i s l i s t of conditions and the f o l l o w i n g disclaimer .
∗
∗ − Redistributions in binary form must reproduce the above copyright
∗ notice , t h i s l i s t of conditions and the f o l l o w i n g disclaimer in the
∗ documentation and / or other materials provided with the d i s t r i b u t i o n .
∗
∗ − Neither the name of Oracle or the names of i t s
∗ c o n t r i b u t o r s may be used to endorse or promote products derived
∗ from t h i s software without s p e c i f i c p r i o r w r i t t e n permission .
∗
∗ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
∗ IS " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
∗ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
∗ PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR
∗ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT , INCIDENTAL , SPECIAL ,
∗ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
∗ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
∗ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
∗ LIABILITY , WHETHER IN CONTRACT, STRICT LIABILITY , OR TORT (INCLUDING
∗ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
∗ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Introduction The Server The Echo Client References
THE CLIENT II
∗/
import java . io . ∗ ;
import java . net . ∗ ;
public class TelnetClient {
public static void main ( String [ ] args ) throws IOException {
i f ( args . length != 2) {
System . err . p r i n t l n (
"Usage : java TelnetClient <host name> <port number>" ) ;
System . e x i t ( 1 ) ;
}
String hostName = args [ 0 ] ;
int portNumber = Integer . parseInt ( args [ 1 ] ) ;
try (
Socket echoSocket = new Socket ( hostName , portNumber ) ;
P r i n t W r i t e r out =
new P r i n t W r i t e r ( echoSocket . getOutputStream ( ) , true ) ;
BufferedReader in =
new BufferedReader (
new InputStreamReader ( echoSocket . getInputStream ( ) ) ) ;
BufferedReader stdIn =
new BufferedReader (
new InputStreamReader ( System . in ) )
) {
String userInput , serverOutput ;
Introduction The Server The Echo Client References
THE CLIENT III
while ( ( userInput = stdIn . readLine ( ) ) != null ) {
out . p r i n t l n ( userInput ) ;
System . out . p r i n t l n ( " t e l n e t : " ) ;
while ( ! ( serverOutput=in . readLine ( ) ) . equals ( " bye " ) )
System . out . p r i n t l n ( serverOutput ) ;
System . out . p r i n t l n ( "Bye Client " ) ;
}
} catch ( UnknownHostException e ) {
System . err . p r i n t l n ( "Don ’ t know about host " + hostName ) ;
System . e x i t ( 1 ) ;
} catch ( IOException e ) {
System . err . p r i n t l n ( " Couldn ’ t get I /O f o r the connection to " +
hostName ) ;
System . e x i t ( 1 ) ;
}
}
}
Introduction The Server The Echo Client References
REFERENCES
The source code has been taken from
here.
This presentation has been produced with LATEX.
Frankfurt, monarcha.

More Related Content

PDF
How to Make an Echo Server
PDF
File Transfer Through Sockets
DOC
Program for hamming code using c
DOCX
Computer Networks Lab File
DOCX
Network lap pgms 7th semester
DOC
Network lab manual
PDF
CyberLink LabelPrint 2.5 Exploitation Process
PPTX
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory
How to Make an Echo Server
File Transfer Through Sockets
Program for hamming code using c
Computer Networks Lab File
Network lap pgms 7th semester
Network lab manual
CyberLink LabelPrint 2.5 Exploitation Process
Exploit Development: EzServer Buffer Overflow oleh Tom Gregory

What's hot (19)

ODP
Sysprog17
PPTX
Oop object oriented programing topics
PDF
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
PDF
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
PDF
Rust LDN 24 7 19 Oxidising the Command Line
DOCX
TXT
System programs in C language.
PPTX
Unit testing CourseSites Apache Filter
DOCX
System programmin practical file
TXT
Program of speed and direction control of dc motor
KEY
Yapcasia2011 - Hello Embed Perl
PDF
Hachiojipm11
PDF
Php arduino
PPT
C Sharp Jn (3)
KEY
DOCX
Server
PDF
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
PDF
Asynchronen Code testen
PDF
Linux Shellcode disassembling
Sysprog17
Oop object oriented programing topics
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
[2007 CodeEngn Conference 01] seaofglass - Linux Virus Analysis
Rust LDN 24 7 19 Oxidising the Command Line
System programs in C language.
Unit testing CourseSites Apache Filter
System programmin practical file
Program of speed and direction control of dc motor
Yapcasia2011 - Hello Embed Perl
Hachiojipm11
Php arduino
C Sharp Jn (3)
Server
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
Asynchronen Code testen
Linux Shellcode disassembling
Ad

Viewers also liked (8)

PDF
Melissa Barton Editor Resume (2)
PDF
IXP SDK
PDF
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
PPTX
BioGaia ProDentis - pirmas klinikiniais tyrimais patvirtintas probiotikas dan...
PPTX
OS Command Injection Analysis
PDF
Thesis
DOCX
Rデモ03_データ分析編2016
PPTX
How to Boost Your Traffic and Profits with Content
Melissa Barton Editor Resume (2)
IXP SDK
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
BioGaia ProDentis - pirmas klinikiniais tyrimais patvirtintas probiotikas dan...
OS Command Injection Analysis
Thesis
Rデモ03_データ分析編2016
How to Boost Your Traffic and Profits with Content
Ad

Similar to Remote Command Execution (20)

PDF
The Knock Knock Protocol
PDF
App Optimizations Using Qualcomm Snapdragon LLVM Compiler for Android
PDF
HH QUALCOMM using qualcomm® snapdragon™ llvm compiler to optimize apps for 32...
TXT
Readme
PDF
Binary instrumentation - dc9723
PPTX
PDF
Fraglight: Shedding Light on Broken Pointcuts Using Structural Commonality
PDF
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
PPT
Networking & Socket Programming In Java
DOCX
Criminal Record System
PDF
Laporan multiclient chatting client server
DOCX
PPTX
Building Hierarchy
PDF
Fraglight: Shedding Light on Broken Pointcuts in Evolving Aspect-Oriented Sof...
PPTX
Full accesspolicyconsolidation for event processing systems
PPT
Socket Programming it-slideshares.blogspot.com
DOCX
Algoritmos sujei
PPTX
Semi-automatic Incompatibility Localization for Re-engineered Industrial Soft...
PPT
Introduction to Spec#
PDF
Detecting Broken Pointcuts using Structural Commonality and Degree of Interest
The Knock Knock Protocol
App Optimizations Using Qualcomm Snapdragon LLVM Compiler for Android
HH QUALCOMM using qualcomm® snapdragon™ llvm compiler to optimize apps for 32...
Readme
Binary instrumentation - dc9723
Fraglight: Shedding Light on Broken Pointcuts Using Structural Commonality
JavaOne San Francisco 2013 - Servlet 3.1 (JSR 340)
Networking & Socket Programming In Java
Criminal Record System
Laporan multiclient chatting client server
Building Hierarchy
Fraglight: Shedding Light on Broken Pointcuts in Evolving Aspect-Oriented Sof...
Full accesspolicyconsolidation for event processing systems
Socket Programming it-slideshares.blogspot.com
Algoritmos sujei
Semi-automatic Incompatibility Localization for Re-engineered Industrial Soft...
Introduction to Spec#
Detecting Broken Pointcuts using Structural Commonality and Degree of Interest

More from adil raja (20)

PDF
ANNs.pdf
PDF
A Software Requirements Specification
PDF
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
PDF
DevOps Demystified
PDF
On Research (And Development)
PDF
Simulators as Drivers of Cutting Edge Research
PDF
CMM Level 3 Assessment of Xavor Pakistan
PDF
Data Warehousing
PDF
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
PDF
Real-Time Non-Intrusive Speech Quality Estimation for VoIP
PDF
VoIP
PDF
ULMAN GUI Specifications
PDF
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
PDF
ULMAN-GUI
PDF
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
PDF
Modeling the Effect of packet Loss on Speech Quality: GP Based Symbolic Regre...
PDF
Modelling the Effect of Packet Loss on Speech Quality
PDF
A Random Presentation
PDF
Packet Processing Application
PDF
Packet Processing Application
ANNs.pdf
A Software Requirements Specification
NUAV - A Testbed for Development of Autonomous Unmanned Aerial Vehicles
DevOps Demystified
On Research (And Development)
Simulators as Drivers of Cutting Edge Research
CMM Level 3 Assessment of Xavor Pakistan
Data Warehousing
Implementation of a Non-Intrusive Speech Quality Assessment Tool on a Mid-Net...
Real-Time Non-Intrusive Speech Quality Estimation for VoIP
VoIP
ULMAN GUI Specifications
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
ULMAN-GUI
Modeling the Effect of Packet Loss on Speech Quality: Genetic Programming Bas...
Modeling the Effect of packet Loss on Speech Quality: GP Based Symbolic Regre...
Modelling the Effect of Packet Loss on Speech Quality
A Random Presentation
Packet Processing Application
Packet Processing Application

Recently uploaded (20)

PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PPT
Mechanical Engineering MATERIALS Selection
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Well-logging-methods_new................
PPT
Project quality management in manufacturing
DOCX
573137875-Attendance-Management-System-original
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
composite construction of structures.pdf
PPTX
Construction Project Organization Group 2.pptx
PPTX
Geodesy 1.pptx...............................................
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Sustainable Sites - Green Building Construction
PPTX
Internet of Things (IOT) - A guide to understanding
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
Mechanical Engineering MATERIALS Selection
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Well-logging-methods_new................
Project quality management in manufacturing
573137875-Attendance-Management-System-original
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
composite construction of structures.pdf
Construction Project Organization Group 2.pptx
Geodesy 1.pptx...............................................
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
CH1 Production IntroductoryConcepts.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
OOP with Java - Java Introduction (Basics)
Sustainable Sites - Green Building Construction
Internet of Things (IOT) - A guide to understanding

Remote Command Execution

  • 1. Introduction The Server The Echo Client References REMOTE COMMAND EXECUTION Muhammad Adil Raja Roaming Researchers, R . November 18, 2015
  • 2. Introduction The Server The Echo Client References OUTLINE 1 INTRODUCTION 2 THE SERVER 3 THE ECHO CLIENT 4 REFERENCES
  • 3. Introduction The Server The Echo Client References OUTLINE 1 INTRODUCTION 2 THE SERVER 3 THE ECHO CLIENT 4 REFERENCES
  • 4. Introduction The Server The Echo Client References OUTLINE 1 INTRODUCTION 2 THE SERVER 3 THE ECHO CLIENT 4 REFERENCES
  • 5. Introduction The Server The Echo Client References OUTLINE 1 INTRODUCTION 2 THE SERVER 3 THE ECHO CLIENT 4 REFERENCES
  • 6. Introduction The Server The Echo Client References INTRODUCTION
  • 7. Introduction The Server The Echo Client References THE SERVER I /∗ ∗ Copyright ( c ) 2013, Oracle and / or i t s a f f i l i a t e s . A l l r i g h t s reserved . ∗ ∗ R e d i s t r i b u t i o n and use in source and binary forms , with or without ∗ modification , are permitted provided that the f o l l o w i n g conditions ∗ are met : ∗ ∗ − Redistributions of source code must r e t a i n the above copyright ∗ notice , t h i s l i s t of conditions and the f o l l o w i n g disclaimer . ∗ ∗ − Redistributions in binary form must reproduce the above copyright ∗ notice , t h i s l i s t of conditions and the f o l l o w i n g disclaimer in the ∗ documentation and / or other materials provided with the d i s t r i b u t i o n . ∗ ∗ − Neither the name of Oracle or the names of i t s ∗ c o n t r i b u t o r s may be used to endorse or promote products derived ∗ from t h i s software without s p e c i f i c p r i o r w r i t t e n permission . ∗ ∗ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS ∗ IS " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ∗ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ∗ PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR ∗ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT , INCIDENTAL , SPECIAL , ∗ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ∗ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR ∗ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ∗ LIABILITY , WHETHER IN CONTRACT, STRICT LIABILITY , OR TORT (INCLUDING ∗ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ∗ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • 8. Introduction The Server The Echo Client References THE SERVER II ∗/ import java . net . ∗ ; import java . io . ∗ ; public class TelnetServer { public static void main ( String [ ] args ) throws IOException { i f ( args . length != 1) { System . err . p r i n t l n ( "Usage : java EchoServer <port number>" ) ; System . e x i t ( 1 ) ; } int portNumber = Integer . parseInt ( args [ 0 ] ) ; try ( ServerSocket serverSocket = new ServerSocket ( Integer . parseInt ( args [ 0 ] ) ) ; Socket clientSocket = serverSocket . accept ( ) ; P r i n t W r i t e r out = new P r i n t W r i t e r ( clientSocket . getOutputStream ( ) , true ) ; BufferedReader in = new BufferedReader ( new InputStreamReader ( clientSocket . getInputStream ( ) ) ) ; ) { String inputLine ; String n u l l S t r =null ; while ( ( inputLine = in . readLine ( ) ) != null ) { ProcessBuilder processB=new ProcessBuilder ( " bash " , "−c " , inputLine ) ; processB . redirectErrorStream ( true ) ;
  • 9. Introduction The Server The Echo Client References THE SERVER III Process process = processB . s t a r t ( ) ; BufferedReader br = new BufferedReader ( new InputStreamReader ( process . getInputStream ( ) ) ) ; / / BufferedReader errorReader = new BufferedReader ( / / new InputStreamReader ( process . getErrorStream ( ) ) ) ; while ( ( inputLine=br . readLine ( ) ) ! = null ) { out . p r i n t l n ( inputLine ) ; System . out . p r i n t l n ( " Log : "+ inputLine ) ; } out . p r i n t l n ( " bye " ) ; out . flush ( ) ; System . out . p r i n t l n ( "Bye Input ! " ) ; System . out . p r i n t l n ( "Bye Error ! " ) ; br . close ( ) ; process . destroy ( ) ; / / out . p r i n t l n ( " Bye : " ) ; } } catch ( IOException e ) { System . out . p r i n t l n ( " Exception caught when t r y i n g to l i s t e n on port " + portNumber + " or l i s t e n i n g f o r a connection " ) ; System . out . p r i n t l n ( e . getMessage ( ) ) ; } } }
  • 10. Introduction The Server The Echo Client References THE CLIENT I /∗ ∗ Copyright ( c ) 1995, 2013, Oracle and / or i t s a f f i l i a t e s . A l l r i g h t s reserved . ∗ ∗ R e d i s t r i b u t i o n and use in source and binary forms , with or without ∗ modification , are permitted provided that the f o l l o w i n g conditions ∗ are met : ∗ ∗ − Redistributions of source code must r e t a i n the above copyright ∗ notice , t h i s l i s t of conditions and the f o l l o w i n g disclaimer . ∗ ∗ − Redistributions in binary form must reproduce the above copyright ∗ notice , t h i s l i s t of conditions and the f o l l o w i n g disclaimer in the ∗ documentation and / or other materials provided with the d i s t r i b u t i o n . ∗ ∗ − Neither the name of Oracle or the names of i t s ∗ c o n t r i b u t o r s may be used to endorse or promote products derived ∗ from t h i s software without s p e c i f i c p r i o r w r i t t e n permission . ∗ ∗ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS ∗ IS " AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, ∗ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR ∗ PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR ∗ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT , INCIDENTAL , SPECIAL , ∗ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, ∗ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR ∗ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ∗ LIABILITY , WHETHER IN CONTRACT, STRICT LIABILITY , OR TORT (INCLUDING ∗ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ∗ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  • 11. Introduction The Server The Echo Client References THE CLIENT II ∗/ import java . io . ∗ ; import java . net . ∗ ; public class TelnetClient { public static void main ( String [ ] args ) throws IOException { i f ( args . length != 2) { System . err . p r i n t l n ( "Usage : java TelnetClient <host name> <port number>" ) ; System . e x i t ( 1 ) ; } String hostName = args [ 0 ] ; int portNumber = Integer . parseInt ( args [ 1 ] ) ; try ( Socket echoSocket = new Socket ( hostName , portNumber ) ; P r i n t W r i t e r out = new P r i n t W r i t e r ( echoSocket . getOutputStream ( ) , true ) ; BufferedReader in = new BufferedReader ( new InputStreamReader ( echoSocket . getInputStream ( ) ) ) ; BufferedReader stdIn = new BufferedReader ( new InputStreamReader ( System . in ) ) ) { String userInput , serverOutput ;
  • 12. Introduction The Server The Echo Client References THE CLIENT III while ( ( userInput = stdIn . readLine ( ) ) != null ) { out . p r i n t l n ( userInput ) ; System . out . p r i n t l n ( " t e l n e t : " ) ; while ( ! ( serverOutput=in . readLine ( ) ) . equals ( " bye " ) ) System . out . p r i n t l n ( serverOutput ) ; System . out . p r i n t l n ( "Bye Client " ) ; } } catch ( UnknownHostException e ) { System . err . p r i n t l n ( "Don ’ t know about host " + hostName ) ; System . e x i t ( 1 ) ; } catch ( IOException e ) { System . err . p r i n t l n ( " Couldn ’ t get I /O f o r the connection to " + hostName ) ; System . e x i t ( 1 ) ; } } }
  • 13. Introduction The Server The Echo Client References REFERENCES The source code has been taken from here. This presentation has been produced with LATEX. Frankfurt, monarcha.