messagesserver.java
来自「Remote Internet Connect简化了从其它运行操作系统的机子上将」· Java 代码 · 共 100 行
JAVA
100 行
/*
* RIC 2 Server Release. by Harry Otten (c) Copyright 2003 hotten@dds.nl
* Check out http://www.hotten.dds.nl/ric/
*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
*/
import java.net.*; // for Socket, ServerSocket, and InetAddress
import java.io.*; // for IOException and Input/OutputStream
import java.util.Vector;
import java.lang.* ;
public class MessagesServer extends Thread {
private Server server;
private ServerSocket servSock;
public MessagesServer(Server server) {
this.server=server;
};
public void run() {
try {
try {
// Create a server socket to accept client connection requests
servSock = new ServerSocket(2000,0,InetAddress.getByName("127.0.0.1"));
}
catch (UnknownHostException e) {
System.out.println("Messages server..Hostname doesn't resolve!");
return;
}
}
catch (IOException e) {
System.out.println("Can not bind IP adress 127.0.0.1 ???? check loop device");
return; //the end of this thread and the end of all
}
try {
try {
// Create a server socket to accept client connection messages
System.out.println("Messages Server online!");
for (;;){ // for ever
Socket clntSock = servSock.accept(); // Get client connection. IDLE POINT
MessageConnection messageConnection = new MessageConnection(clntSock,this);
messageConnection.start(); // it's a thread ;-)
}
} catch (SocketException e) {
System.out.println("Messages Server is schutting down...");
}
} catch (IOException e) {
System.out.println("System crash!!!! MessagesServer socket not nice :-(. RIC primary systems will still work! ;-)");
e.printStackTrace();
}
};
public void quit() {
try {
servSock.close();
} catch (Exception e) {
}
};
public void giveMessages(String titel,String messages,String commando) {
// In the future there can be things added here....
/* so I will. Checking of the messages syntax is correct.
The command must be play=
*/
if (commando.indexOf("PLAY=")!=-1) {
server.sendMessages(titel,messages,commando);
} else if (commando.equals(";")) {
server.sendMessages(titel,messages,commando);
} else if (commando.equals("niks;")) { //staying combatible with a wrong example :-(
server.sendMessages(titel,messages,";");
System.out.println("Please adjust your script! replace \"niks\" by \"PLAY=$1.wav\"");
} else System.out.println("The messages recieved by the server does not contain a valid command");
};
};
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?