-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
88 lines (72 loc) · 2.34 KB
/
Copy pathClient.java
File metadata and controls
88 lines (72 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright (c) 2000-2001 ipKangaroo
*
*/
/*
This is the executable for the ipKchat text client. As it stands from
version 1.8 this is an undocumented feature and add on. In general
this should not be used. But, if it has to be used it is the basis
from which the GUI version was constructed. Very simple, this class
instantiates two threads, 'ClientFrom' to type the input to the screen
and 'ClientTo' to send the output to the server.
*/
import java.io.*;
import java.net.*;
//The Client class
public class Client
{
static int port = 2222; // default server port
static String host = "localhost"; // default server host
static String id = "DualDog";
public static void main(String [] argv)
{
String usage = "usage: java DemoClient [-h host] [-p port] ID " +
"\n (default port=" + port +", host=" + host + ")";
try
{
Arguments arguments = new Arguments(argv); //Start parsing commmand line
if (arguments.isSpecified("h"))
host = arguments.getModified("h");
if (arguments.isSpecified("p"))
port = arguments.getModifiedInt("p");
if (arguments.getUnmodified().size() > 0)
id = (String) arguments.getUnmodified().get(0); //End parse
}
catch (NumberFormatException e)
{
System.err.println("bad number format");
System.exit(1);
}
System.out.println("");
System.out.println("Port: " + port);
System.out.println("Host: " + host);
System.out.println("ID: " + id);
System.out.println("");
doDaWork();
}
protected static void doDaWork() //Sets up socket communication
{
try
{
Socket s = new Socket(host, port);
OutputStream os = s.getOutputStream();
BufferedReader is = new BufferedReader(new InputStreamReader(s.getInputStream()));
System.out.println("Bringing up Threads...");
ClientFrom f = new ClientFrom(is);
f.start(); //Starts recieving thread...
ClientTo t = new ClientTo(os, id);
t.start(); //Start sending thread...
} //That's it, now look at "ClientFrom.java" and "ClientTo.java"
catch (UnknownHostException e)
{
System.err.println("unknown host: " + host);
System.exit(1);
}
catch (IOException e)
{
System.out.println(e.getMessage());
System.out.println("Quiting...");
//e.printStackTrace();
}
}
}