-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTCPClient.java
More file actions
61 lines (44 loc) · 1.62 KB
/
TCPClient.java
File metadata and controls
61 lines (44 loc) · 1.62 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
import java.io.*;
import java.net.*;
public class TCPClient {
public static void main(String argv[]) throws Exception
{
String hostname = InetAddress.getLocalHost().getHostName();
String sentence;
String modifiedSentence;
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket(hostname, 6791);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer =
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
System.out.println("Enter request :");
while(true)
{
sentence = inFromUser.readLine();
String[] things = new String[1];
things=sentence.split(":");
if(!sentence.equals("end"))
{
System.out.println("Enter request:"+sentence);
}
else if (things[0].equals("CHECK"))
{
String getNum;
getNum= inFromServer.readLine();
System.out.println("Name'number is: " + getNum);
}
outToServer.writeBytes(sentence + '\n');
if(sentence.equals("end"))
{
System.out.println("Disconnect with server ");
break;
}
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
}
clientSocket.close();
}
}