📄 communicator.java
字号:
/*
* Created on 2007.12.25.
*/
package conferenceroom;
import java.io.*;
public final class Communicator {
public void service(
final User user,
final String roomid,
final String roomname,
final InputStream inputStream) {
try {
// Input Stream and output Stream...
BufferedReader reader =
new BufferedReader(new InputStreamReader(inputStream));
OutputStream outputStream = user.getOutputStream();
outputStream.write(
("ConnectID:" + user.getUserid() + "\r\n").getBytes());
outputStream.write(
("ConnectName:" + user.getUsername() + "\r\n").getBytes());
final Channel channel = Server.instance.getChannel();
final Room room = channel.getRoom(roomid);
if (room == null) {
outputStream.write("ERROR:RoomIsNotExist\r\n".getBytes());
outputStream.flush();
return;
}
int enter;
if ("00admin".equals(user.getUsername())) {
enter = room.enterAdmin(user);
} else {
enter = room.enterUser(user);
}
if (enter != 0) {
if (enter == -1) {
outputStream.write("ERROR:RoomIsFull\r\n".getBytes());
} else if (enter == -2) {
outputStream.write("ERROR:PasswordNotMatch\r\n".getBytes());
} else {
outputStream.write("ERROR:Unknown\r\n".getBytes());
}
outputStream.flush();
return;
}
boolean connected = true;
room.inputRoomInfo();
try {
while (connected) {
String r = reader.readLine();
if (r == null) {
// Connection Closed...
break;
}
try {
int index = r.indexOf(":");
if (index < 0) {
System.out.println(
"NO Command Found .... Skipping....:" + r);
continue;
}
String cmd = r.substring(0, index);
if (cmd.equalsIgnoreCase("MSG")) { // message
} else {
System.out.println(
"Wrong Command.... Skipping....:" + r);
continue;
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
room.exitUser(user);
connected = false;
try {
if (outputStream != null) {
outputStream.write("CLOSED:\r\n".getBytes());
outputStream.flush();
}
} catch (IOException e) {
System.err.println("IOException : 203");
e.printStackTrace();
}
}
System.out.println(
"Listen thread ended....[" + user.getUserid() + "]");
} catch (IOException e) {
System.err.println("IOException : 155");
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -