-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgameserver.java
65 lines (55 loc) · 1.33 KB
/
gameserver.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
55
56
57
58
59
60
61
62
63
import java.net.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class gameserver implements Runnable
{
controls game;
Socket socket;
public static BufferedReader br;
PrintWriter pw;
public gameserver() throws IOException
{
ServerSocket server = new ServerSocket(3456);
socket = server.accept();
initializeStreams();
game = new controls(pw);
new Thread(this).start();
}
public void initializeStreams() throws IOException
{
br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())));
}
public void run()
{
// server game code, reads endlessly
while(true)
{
try
{
socket.setSoTimeout(20000);
game.interpretCommand(br.readLine());
//game.runningfunction(game);
// system.out.println(br.readLine());
} catch(IOException ioe)
{game.serverrunning=0;
// System.exit(0);
}
}
}
// write
/*public void sendCommand(String commandName)
{
pw.println(commandName);
pw.flush();
}*/
public static void main(String args[]) throws IOException
{
// gameserver b= new gameserver();
// new Thread(a).start();
// (b.game).runningfunction(b.game);
// loop (running function)
}
}