📄 messageconnection.java
字号:
/*
* 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
public class MessageConnection extends Thread {
private InputStream in;
private OutputStream out;
private Socket socket;
private MessagesServer messagesServer;
private static final int BUFSIZE = 32; // Size of receive buffer
public MessageConnection(Socket socket, MessagesServer messagesServer) {
this.socket=socket;
this.messagesServer=messagesServer;
}
public void run() {
StringBuffer stringBuf = new StringBuffer();
String commando="",titel="",messages="",command;
int byteRead;
int teller=0;
System.out.println("Handling messages client at " + socket.getInetAddress().getHostAddress() + " on port " + socket.getPort());
try {
in = socket.getInputStream();
out = socket.getOutputStream();
while(teller<3)
{
byteRead = 0; //
stringBuf.setLength(0);
while (byteRead != 59) { // so long as byteRead doesn't match ;
if ((byteRead = in.read()) == -1)
throw new SocketException("Connection close prematurely");
else stringBuf.append((char)byteRead);
}
commando = stringBuf.toString();
System.out.println("Recieved:"+commando);
switch (teller) {
case 0: titel=commando; break;
case 1: messages=commando; break;
case 2: command=commando;
System.out.println("3 parameters accepted");
socket.close();
}
teller++;
}
} catch (IOException e) {
System.out.println("Connection lost....Thread dies!");
try { socket.close();} catch (IOException f) {};
}
messagesServer.giveMessages(titel,messages,commando);
System.out.println("Handeld messages client at " +
socket.getInetAddress().getHostAddress() + " on port " + socket.getPort());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -