📄 server.java
字号:
package fourconnect;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.io.*;
import javax.microedition.io.*;
import java.util.*;
public class Server extends Thread {
Thread thread;
InputStream in;
OutputStream out;
ServerSocketConnection ssc;// 基于服务器的套界字连接
SocketConnection sc;
public static Sender send1;
public String sentstring;
public int r = 0;
public int PIECE;
public Server() {
// try{
// ssc=(ServerSocketConnection)Connector.open("socket://:4000");
// sc=(SocketConnection)ssc.acceptAndOpen();
// in=sc.openDataInputStream();
// out=sc.openDataOutputStream();
// send1=new Sender(out);
// //start();
// }catch(Exception e){e.printStackTrace();System.out.println("init
// socket error!");}
}
public void start() {
thread = new Thread(this);
thread.start();
}
public void run() {
try {
ssc = (ServerSocketConnection) Connector.open("socket://:4000");
sc = (SocketConnection) ssc.acceptAndOpen();
in = sc.openDataInputStream();
out = sc.openDataOutputStream();
send1 = new Sender(out);
// start();
} catch (Exception e) {
e.printStackTrace();
System.out.println("init socket error!");
}
try {
while (gamecanvas.isgame) {
StringBuffer strbuf = new StringBuffer();
int c;
while ((c = in.read()) != '\n' && (c != -1)) {
strbuf.append((char) c);
strbuf.toString();
}
// if(c==1) break;
Thread.sleep(40);
/** ***************************** */
try{
if (strbuf.toString().startsWith("REDACTION")) {
gamecanvas.b_redaction = true;
gamecanvas.b_greenaction = false;
}
else if (strbuf.toString().startsWith("GREENACTION")) {
gamecanvas.b_greenaction = true;
gamecanvas.b_redaction = false;
}
}catch(Exception e){e.printStackTrace();System.out.println("action~~~");}
int status[] = new int[70];
try {
if (strbuf.toString().startsWith("A")) {
sentstring = strbuf.toString().substring(1,
strbuf.toString().length());
}
for (int i = 0; i < 42; i++) {
status[i] = Integer.parseInt(sentstring.substring(i,
i + 1));
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("mmmmmmmmmm");
}
try {
for (int i = 0; i < 6; i++)
for (int j = 0; j < 7; j++) {
gamecanvas.map[i][j] = status[r];
r++;
}
r = 0;
} catch (Exception e) {
e.printStackTrace();
System.out.println("xxxxxxxxxxxx");
}
/** *********************************** */
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("run error!");
}
}
public void stop() throws Exception {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
if (ssc != null) {
ssc.close();
}
if (sc != null) {
sc.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -