-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e92953
commit a6ea666
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// A Java program for a Client | ||
import java.io.*; | ||
import java.net.*; | ||
|
||
public class Client { | ||
// initialize socket and input output streams | ||
private Socket socket = null; | ||
private DataInputStream input = null; | ||
|
||
private DataOutputStream out = null; | ||
|
||
// constructor to put ip address and port | ||
public Client(String address, int port) | ||
{ | ||
// establish a connection | ||
try { | ||
socket = new Socket(address, port); | ||
System.out.println("Connected"); | ||
|
||
|
||
|
||
// takes input from terminal | ||
input = new DataInputStream(System.in); | ||
|
||
|
||
|
||
// sends output to the socket | ||
out = new DataOutputStream( | ||
socket.getOutputStream()); | ||
|
||
// string to read message from input | ||
String line = ""; | ||
|
||
|
||
|
||
// keep reading until "Over" is input | ||
while (!line.equalsIgnoreCase("over")) { | ||
|
||
line = input.readLine(); | ||
out.writeUTF(line); | ||
|
||
|
||
|
||
|
||
} | ||
|
||
// close the connection | ||
|
||
input.close(); | ||
|
||
out.close(); | ||
socket.close(); | ||
} | ||
catch (UnknownHostException u) { | ||
System.out.println(u); | ||
return; | ||
} | ||
catch (IOException i) { | ||
System.out.println(i); | ||
return; | ||
} | ||
} | ||
|
||
public static void main(String args[]) | ||
{ | ||
Client client = new Client("127.0.0.1", 5000); | ||
} | ||
} |