當前位置: 首頁>>代碼示例>>Java>>正文


Java Message類代碼示例

本文整理匯總了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();
}
 
開發者ID:DaMa-Team,項目名稱:DaMaCrypt-Common,代碼行數:18,代碼來源:Protocol.java

示例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);
}
 
開發者ID:DaMa-Team,項目名稱:DaMaCrypt-Common,代碼行數:15,代碼來源:Protocol.java

示例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();
	}

}
 
開發者ID:DaMa-Team,項目名稱:DaMaCrypt-Client,代碼行數:15,代碼來源:DaCryClient.java

示例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);
	}

}
 
開發者ID:DaMa-Team,項目名稱:DaMaCrypt-Server,代碼行數:82,代碼來源:ClientHandling.java

示例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);
}
 
開發者ID:DaMa-Team,項目名稱:DaMaCrypt-Common,代碼行數:10,代碼來源:Protocol.java

示例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);

}
 
開發者ID:DaMa-Team,項目名稱:DaMaCrypt-Common,代碼行數:11,代碼來源:Protocol.java

示例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);
}
 
開發者ID:DaMa-Team,項目名稱:DaMaCrypt-Server,代碼行數:10,代碼來源:ClientHandling.java


注:本文中的Client.Protocol.Types.Message類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。