我学习移动开发的一个聊天程序

[size=large]Solution Report

Protocol define and explain
    We define the following a simple transportation protocol which the midlet send to server:
Id_message_body
The first is the midlet’s id;
The second is the method, it can be “add”,”message”,”delete”
The third part is the message;
Id_add_MessageBody: This message will be send by midlet when he connect to the chat room.
Id_message_MessageBody: This message will be send by midlet when he send a message to other.
Id_delete_MessageBody: This message will be send by midlet when he leave the chat room.

We define a simple transportation protocol which the server send to midlet:
messageType_messageBody
The first is the message Type, it can be “private”,”message”
The second is the messageBody.
Private_messageBody: This information will be send only for this person, and it will displayed at the top, for example, the previous connected person’s information.
Message_messageBody: This information will be send for all the person, and it will displayed as a chat history below the private message. For example, the other person’s chat message.
Server side implementation
  We implement a servlet which will startup when the server is started, and the servlet will initialize a Thread  which listened in 8000(You can configure it in configuration file web.xml). Every time when a new connection come in, a new Thread will create to deal with the message. And we maintain a Socket collection which hold all the socket connection.
Midlet client implementation
     When the program initialized, it will construct a SocketConnection, and when user click the connect, we will create two thread, one is the writeThread which will write the message queue’s message to server, the other is the readThread, which will read the message from server, and display it in corresponding location according to the message type.
When the user click the send button, the message will be put into message queue, and it will notify the writeThread to write it to the server.
When the user click the exit button, the readThread and the writeThread will be stoped, and also we will release some resources, for example the socket’s InputStream and OutputStream, and also the SocketConnection.
[/size]

我学习移动开发的一个聊天程序_第1张图片

我学习移动开发的一个聊天程序_第2张图片

我学习移动开发的一个聊天程序_第3张图片

我学习移动开发的一个聊天程序_第4张图片



你可能感兴趣的:(thread,Web,servlet,socket,Netbeans)