当前位置: 首页>>代码示例>>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;未经允许,请勿转载。