锁定老帖子 主题:我学习移动开发的一个聊天程序
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-08-01
最后修改:2009-08-08
[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] 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2009-08-03
最后修改:2009-08-03
对不起呀,这个是我给一个留学的同学做的,大家就勉强的看吧。也随便锻炼锻炼英文,呵呵。
|
|
返回顶楼 | |
发表时间:2009-08-03
确实不错哦,英文好啊
|
|
返回顶楼 | |
发表时间:2009-08-04
做的时候感觉虽然J2ME里面的线程比较难控制,我的里面线程控制有点问题,呵呵。
|
|
返回顶楼 | |
发表时间:2009-08-04
asialee 写道 做的时候感觉虽然J2ME里面的线程比较难控制,我的里面线程控制有点问题,呵呵。
嗯, J2ME的thread还真麻烦... |
|
返回顶楼 | |
发表时间:2009-08-04
怎么麻烦了?我觉得还好啊
lordhong 写道 asialee 写道 做的时候感觉虽然J2ME里面的线程比较难控制,我的里面线程控制有点问题,呵呵。
嗯, J2ME的thread还真麻烦... |
|
返回顶楼 | |
发表时间:2009-08-04
wayfarer 写道 怎么麻烦了?我觉得还好啊
lordhong 写道 asialee 写道 做的时候感觉虽然J2ME里面的线程比较难控制,我的里面线程控制有点问题,呵呵。
嗯, J2ME的thread还真麻烦... Java SE和EE都开发过,但ME没有开发过,我稍微看了一下,然后按照开发java程序的思想写的,但感觉稍微不一样。 |
|
返回顶楼 | |
发表时间:2009-08-04
看了朋友的作品,感觉真好...期待朋友更多的精彩!
|
|
返回顶楼 | |
发表时间:2009-08-04
youngmaster 写道 看了朋友的作品,感觉真好...期待朋友更多的精彩!
是在说我吗? 要是我的话,先谢谢了。 |
|
返回顶楼 | |
发表时间:2009-08-05
这个是我用了大概3天时间写的,还是比较仓促。当感觉思想是相通的。
|
|
返回顶楼 | |