-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultipleClientsToServer_C.java
68 lines (45 loc) · 1.25 KB
/
MultipleClientsToServer_C.java
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
import java.io.*;
import java.net.*;
class MultipleClientsToServer_C
{
public static void main(String args[])
{
Socket socket;
int port;
String ip;
String outMessage;
//port=Integer.parseInt(args[1]);
//ip=args[0];
port=8080;
ip="127.0.0.1";
try
{
socket=new Socket(ip,port);
System.out.println("Connected to the server : "+socket.getRemoteSocketAddress());
BufferedReader xx=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
System.out.println("Say what you wanna say! (Type 'So Long sucker' (not case sensitive) or just 'goodbye' to disconnect))");
while((!(outMessage=xx.readLine()).equalsIgnoreCase("so long sucker")) && !(outMessage.equalsIgnoreCase("goodbye")))
{
bw.write(outMessage);
bw.newLine();
bw.flush();
}
bw.write(outMessage);
bw.newLine();
bw.flush();
socket.close();
System.out.println("Disconnected from the server!");
bw.close();
}
catch(SocketException e) //SocketException extends IOEcxeption
{
System.out.println("The server is AWOL!");
System.exit(0);
}
catch(IOException e)
{
e.printStackTrace();
}
}
}