0% found this document useful (0 votes)
34 views3 pages

Simple Client

The document contains code for an app server and app client written in Java that allows for basic communication between the two over a network. The app server code defines a server socket that listens for connections from clients and handles reading/writing input and output streams once a client is connected. The app client code defines how a client socket connects to the server, takes user input, writes it to the server, reads the response, and closes the connection.

Uploaded by

andifaizal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

Simple Client

The document contains code for an app server and app client written in Java that allows for basic communication between the two over a network. The app server code defines a server socket that listens for connections from clients and handles reading/writing input and output streams once a client is connected. The app client code defines how a client socket connects to the server, takes user input, writes it to the server, reads the response, and closes the connection.

Uploaded by

andifaizal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

Nama Nim

: Andi Faizal : 110155201069

package Tugas; import java.net.*; import java.io.*; /** * * @author Asus */ public class AppServer { public final static int TEST !"T # $%&'; public static voi( main)String args*+, { ServerSocket checkServer # null; String line; -uffere("ea(er is # null; .ata!utputStream os # null; Socket clientSocket # null; tr/ { checkServer # ne0 ServerSocket)TEST !"T,; S/stem.out.println)1Aplikasi Server hi(up ...1,; 2 catch )3!E4ception e, { S/stem.out.println)e,; 2 tr/ { clientSocket # checkServer.accept),; is # ne0 -uffere("ea(er)ne0 3nputStream"ea(er)clientSocket.get3nputStream),,,; os # ne0 .ata!utputStream)clientSocket.get!utputStream),,; 2 catch )E4ception ei, { ei.printStackTrace),; 2 tr/ { line # is.rea(5ine),; S/stem.out.println)1Terima 6 1 7 line,; if )line.compareTo)1salam1, ## ', { os.0rite-/tes)1salam juga1,; 2 else { os.0rite-/tes)18aaf9 sa/a ti(ak mengerti1,; 2 2 catch )3!E4ception e, { S/stem.out.println)e,; 2 tr/ { os.close),; is.close),; clientSocket.close),; 2 catch )3!E4ception ic, { ic.printStackTrace),;

222 package Tugas; import java.net.*; import java.io.*; /** * * @author Asus */ public class App:lient { public final static int "E8!TE; !"T # $%&'; public static voi( main)String args*+, thro0s E4ception { Socket cl # null; -uffere("ea(er is # null; .ata!utputStream os # null; -uffere("ea(er st(in # ne0 -uffere("ea(er)ne0 3nputStream"ea(er)S/stem.in,,; String user3nput # null; String output # null; tr/ { cl # ne0 Socket)args*'+9 "E8!TE; !"T,; is # ne0 -uffere("ea(er)ne0 3nputStream"ea(er)cl.get3nputStream),,,; os # ne0 .ata!utputStream)cl.get!utputStream),,; 2 catch)<nkno0n=ostE4ception e$, { S/stem.out.println)1<nkno0n =ost6 1 7 e$,; 2 catch )3!E4ception e>, { S/stem.out.println)1Erorr io6 1 7 e>,; 2 tr/ { S/stem.out.print)18asukkan kata kunci6 1,; user3nput # st(in.rea(5ine),; os.0rite-/tes)user3nput 7 1?n1,; 2 catch )3!E4ception e4, { S/stem.out.println)1Error 0riting to server...1 7 e4,; 2 tr/ { output # is.rea(5ine),; S/stem.out.println)1.ari server6 1 7 output,; 2 catch )3!E4ception e, { e.printStackTrace),; 2 tr/ { is.close),; os.close),; cl.close),; 2 catch )3!E4ception 4, { S/stem.out.println)1Error 0riting....1 7 4,; 2 2 2

You might also like