-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServer.java
46 lines (37 loc) · 1.45 KB
/
Server.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
import java.io.*;
import java.net.Socket;
/**
* Copyright (C) 2020 Intern Labs O!
* <p>
* <p>
* Sokoban is a logical puzzle game in which the player moves boxes
* through a maze shown as a plan in order to put all the boxes
* in the specified final positions. Only one box can be moved at a time,
* and the hero of the game — the "storekeeper" — can only push the boxes,
* but not pull them. Since the game is quite difficult to recreate physically,
* it is usually implemented as a computer game.
*
* @author Argen Kasymov
*/
public class Server {
public synchronized static int[][] getLevelFromServer(int level) {
try {
Socket echoSocket = null;
ObjectOutputStream outputStream = null;
ObjectInputStream inputStream = null;
echoSocket = new Socket("157.245.219.46", 4469);
outputStream = new ObjectOutputStream(new BufferedOutputStream(echoSocket.getOutputStream()));
outputStream.writeInt(level);
outputStream.flush();
inputStream = new ObjectInputStream(new BufferedInputStream(echoSocket.getInputStream()));
int[][] myMessageArray = (int[][]) inputStream.readObject();
inputStream.close();
outputStream.close();
echoSocket.close();
return myMessageArray;
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
}