/
Client.java
54 lines (52 loc) · 958 Bytes
/
Client.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
import java.net.*;
import java.io.*;
import java.util.Scanner;
public class Client
{
public static void main(String[] args)
{
String str;
Socket sock = null;
ObjectOutputStream writer = null;
Scanner kb = new Scanner(System.in);
try
{
sock = new Socket("127.0.0.1",4444);
}
catch(IOException e)
{
System.out.println("Could not connect.");
System.exit(-1);
}
try
{
writer = new ObjectOutputStream(sock.getOutputStream());
}
catch(IOException e)
{
System.out.println("Could not create write object.");
System.exit(-1);
}
str = kb.nextLine();
try
{
writer.writeObject(str);
writer.flush();
}
catch(IOException e)
{
System.out.println("Could not write to buffer");
System.exit(-1);
}
try
{
sock.close();
}
catch(IOException e)
{
System.out.println("Could not close connection.");
System.exit(-1);
}
System.out.println("Wrote and exited successfully");
}
}