本文整理匯總了Java中Client.Protocol.Types.Message類的典型用法代碼示例。如果您正苦於以下問題:Java Message類的具體用法?Java Message怎麽用?Java Message使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Message類屬於Client.Protocol.Types包,在下文中一共展示了Message類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeMessage
import Client.Protocol.Types.Message; //導入依賴的package包/類
/**
* private abstraction method to make the code of the upper two methods
* easier
*/
private void writeMessage(Message message, byte key) throws IOException {
appendWritelock();
out.writeByte(Protocol.DACRY_SERVER_COMM_OPEN);
out.writeByte(key);
out.writeLong(message.getChatsessionid());
out.writeInt(message.getMsg().length);
for (int i = 0; i < message.getMsg().length; i++) {
out.write(message.getMsg()[i]);
}
out.writeByte(Protocol.DACRY_SERVER_COMM_CLOSE);
out.flush();
releaseWritelock();
}
示例2: readMessage
import Client.Protocol.Types.Message; //導入依賴的package包/類
/**
* This will read a Message from the stream
*
* @return
* @throws IOException
*/
public Message readMessage() throws IOException {
long sessionID = in.readLong();
byte[] content = new byte[in.readInt()];
for (int i = 0; i < content.length; i++) {
content[i] = in.readByte();
}
return new Message((int) sessionID, content);
}
示例3: sentMessage
import Client.Protocol.Types.Message; //導入依賴的package包/類
public void sentMessage(ChatSession session, String msg) {
ChatSessionContainer cont = register.getChatSessionContainer(session
.getId());
try {
byte[] cryptedmsg = encrypt(msg, getFilledArray(cont.getKey()
.toByteArray()));
protocol.writeMessageToServer(new Message((int) session.getId(),
cryptedmsg));
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: run
import Client.Protocol.Types.Message; //導入依賴的package包/類
@Override
public void run() {
try {
byte m = -1;
while (!isInterrupted()) {
Thread.sleep(100);
// m = (Message) in.readObject();
if (in.readByte() == Protocol.DACRY_SERVER_COMM_OPEN) {
m = in.readByte();
switch (m) {
case Protocol.CMD_GET_ONLINE_USERS:
sentOnlineList();
break;
case Protocol.CMD_REGISTER:
protocol.writeID((int) getClientId());
break;
case Protocol.CMD_SET_NAME: {
user.setName(protocol.readNamerequest().getName());
System.out.println(client.getInetAddress()
+ " got Name " + user.getName());
server.nameUpdated();
}
break;
case Protocol.CMD_UNREGISTER: {
server.removeClient(this);
}
break;
case Protocol.CMD_SETUP_CHAT: {
int id = protocol.readChatopen().getChatpartner();
ClientHandling chatpartner = server.getClient(id);
ChatSessionUser init = new ChatSessionUser(getUser(),
null);
ChatSessionUser guest = new ChatSessionUser(
chatpartner.getUser(), null);
ChatSession session = ChatSession.generateChatSession(
-1, init, guest);
int chatSessionID = server.registerChatSession(session);
session.setId(chatSessionID);
chats.add(chatSessionID);
chatpartner.chatInvitation(chatSessionID);
chatInvitation(chatSessionID);
}
break;
case Protocol.CMD_SETUP_CHAT_2:
ChatKeyOffer offer = protocol.readKeyOffer();
ChatSession s = server.getChatSession(offer
.getChatsessionid());
s.getMe(getClientId()).setCry(offer.getKey());
server.cryCheck(offer.getChatsessionid());
break;
case Protocol.CMD_SEND_MESSAGE:
Message message = protocol.readMessage();
ChatSession chatsession = server.getChatSession(message
.getChatsessionid());
if (chatsession == null)
System.out.println("Chatpartner not found !");
else
server.getClient(
chatsession.getPartner(getClientId())
.getUser().getClientId())
.deliverMessage(message);
break;
}
}
}
} catch (Exception e) {
System.out.println(client.getInetAddress() + ": Client Drop!");
e.printStackTrace();
server.removeClient(this);
}
}
示例5: writeMessageToServer
import Client.Protocol.Types.Message; //導入依賴的package包/類
/**
* This will write a Message to the Server
*
* @param message
* @throws IOException
*/
public void writeMessageToServer(Message message) throws IOException {
writeMessage(message, Protocol.CMD_SEND_MESSAGE);
}
示例6: writeMessageToClient
import Client.Protocol.Types.Message; //導入依賴的package包/類
/**
* This will write a Message to the Client
*
* @param message
* @throws IOException
*/
public void writeMessageToClient(Message message) throws IOException {
writeMessage(message, Protocol.NOTIFY_CHAT_MESSAGE);
}
示例7: deliverMessage
import Client.Protocol.Types.Message; //導入依賴的package包/類
/**
* Will write a Message to the Client Side.
*
* @param message
* @throws IOException
*/
public void deliverMessage(Message message) throws IOException {
protocol.writeMessageToClient(message);
}