-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_Client.java
More file actions
75 lines (63 loc) · 1.46 KB
/
Copy pathTest_Client.java
File metadata and controls
75 lines (63 loc) · 1.46 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
import java.util.*;
import java.net.*;
import java.io.*;
class Client
{
Socket socket;
Scanner console_input, socket_input;
PrintStream socket_output;
void get_count_on_location()
{
while(true)
{
System.out.println("Enter the coordinates");
socket_output.println(console_input.nextLine());
}
}
void start_client()
{
try
{
// initilize sockets for client
socket = new Socket("localhost", 8080);
socket_input = new Scanner(socket.getInputStream());
socket_output = new PrintStream(socket.getOutputStream());
console_input = new Scanner(System.in);
// print connection established message
String recieved_message = socket_input.nextLine();
System.out.println(recieved_message);
// send your current location
socket_output.println("0.0 33.33 66.66");
}
catch(Exception e){}
}
}
class Run_Client
{
public static void main(String args[]) throws Exception
{
Client client = new Client();
// start the client server and initialize it
Thread start_client = new Thread(new Runnable()
{
public void run()
{
try{client.start_client();}
catch(Exception e){}
}
});
start_client.start();
start_client.join();
// independent threads for various function of the client
Thread independent_location = new Thread(new Runnable()
{
public void run()
{
try{client.get_count_on_location();}
catch(Exception e){}
}
});
independent_location.start();
independent_location.join();
}
}