forked from vedantDalal/gitWorkshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTICTAC_server.java
More file actions
78 lines (49 loc) · 1.29 KB
/
TICTAC_server.java
File metadata and controls
78 lines (49 loc) · 1.29 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
import java.net.*;
import java.io.*;
class TICTAC_server
{
static TICTAC_server ts = new TICTAC_server();
static NticTac obj1 = new NticTac("O",ts);
static Socket s;
public static void main(String args[]) throws Exception
{
obj1.setSize(400,400);
obj1.setVisible(true);
receive();
}
static void receive()
{
try
{
ServerSocket ss = new ServerSocket(9000);
System.out.println("Player is waiting...");
s = ss.accept();
InputStream is = s.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String x = br.readLine();
String data[] = x.split("~");
System.out.println("The answer="+data[0]+" "+data[1]);
obj1.setPlayerMove("X",Integer.parseInt(data[1]),Integer.parseInt(data[0]));
}
catch(Exception e1)
{
System.out.println(e1);
}
}
void send(String idx_chance)
{
try
{
OutputStream os = s.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
PrintWriter pw = new PrintWriter(osw,true);
idx_chance = obj1.getIndexChance();
pw.println(idx_chance);
}
catch(Exception e1)
{
System.out.println(e1);
}
}
}