因为我目前的Java水平还非常有限,所以,用C#实现。
服务端:
暂时隐藏
客户端:
暂时隐藏
因为本人水平还非常有限,所以,大家将就着看吧,后期我会优化这个程序的。
上面代码中存在的问题:
1、不能进行多客户端连接。(已解决)
2、客户端接收信息太慢,造成服务端信息积压。(已解决)
3、客户端与服务端CPU占用率高,单客户端CPU占50%,服务端CPU占25%。(已解决)
CPU的问题终于解决了,现在CPU终于降到了0%。
服务端:CPU:I3 550 @3.20GHz,内存:8GB。 客户端:CPU:AMD 250 @3.00GHz,内存:2.75GB。
4、客户端连接不稳定,偶尔会有连接中断发生。(已解决)
优化发送接收流程,现在是1秒钟产生一个数据,300毫秒给推出去。
贴一段客户端的效果:
07:36:32:070 得到消息:{"id":592,"content":"ab137cb9-9552-416f-a6e4-a85da08af cbe","producttime":"2012-05-29 07:36:33:290","sendtime":"2012-05-29 07:36:33:572 "}。 07:36:32:970 得到消息:{"id":593,"content":"b8b79d71-62ff-4895-926b-73c07c614 83e","producttime":"2012-05-29 07:36:34:290","sendtime":"2012-05-29 07:36:34:482 "}。 07:36:33:870 得到消息:{"id":594,"content":"7473c7d1-f2d1-4b21-8277-491eafef8 d87","producttime":"2012-05-29 07:36:35:290","sendtime":"2012-05-29 07:36:35:392 "}。 07:36:34:770 得到消息:{"id":595,"content":"929de6c1-ecb8-4434-bf9f-dcf7440e2 1ef","producttime":"2012-05-29 07:36:36:290","sendtime":"2012-05-29 07:36:36:302 "}。 07:36:35:972 得到消息:{"id":596,"content":"b3bed4bf-1b0a-496b-ad0c-13402773e 883","producttime":"2012-05-29 07:36:37:290","sendtime":"2012-05-29 07:36:37:512 "}。 07:36:36:973 得到消息:{"id":597,"content":"3482b337-6e10-48e6-a3bf-f00277a48 900","producttime":"2012-05-29 07:36:38:290","sendtime":"2012-05-29 07:36:38:422 "}。 07:36:37:875 得到消息:{"id":598,"content":"26fc1631-c831-45d1-99c0-fd4ce94a6 6af","producttime":"2012-05-29 07:36:39:290","sendtime":"2012-05-29 07:36:39:332 "}。 07:36:39:077 得到消息:{"id":599,"content":"7c198980-9d57-4364-954b-268b53913 c34","producttime":"2012-05-29 07:36:40:290","sendtime":"2012-05-29 07:36:40:542 "}。
07:41:55:072 得到消息:{"id":557,"content":"fb428136-8d24-471e-9713-c06959518 4f6","producttime":"2012-05-31 07:42:02:287","sendtime":"2012-05-31 07:42:02:333 ","remaining":0}。 07:41:55:634 得到消息:{"id":558,"content":"4e6df285-7ee5-44f1-bd87-6cf1ad65c 023","producttime":"2012-05-31 07:42:02:801","sendtime":"2012-05-31 07:42:02:895 ","remaining":0}。 07:41:56:096 得到消息:{"id":559,"content":"74efb36e-a062-4e6a-8c6f-6a17be354 e3f","producttime":"2012-05-31 07:42:03:316","sendtime":"2012-05-31 07:42:03:347 ","remaining":0}。 07:41:56:658 得到消息:{"id":560,"content":"e2b4dc91-429a-4514-9b86-faa216ee1 336","producttime":"2012-05-31 07:42:03:831","sendtime":"2012-05-31 07:42:03:909 ","remaining":0}。 07:41:57:100 得到消息:{"id":561,"content":"5b85cbcd-9686-4b06-9bdb-1959b593a 208","producttime":"2012-05-31 07:42:04:346","sendtime":"2012-05-31 07:42:04:361 ","remaining":0}。 07:41:57:662 得到消息:{"id":562,"content":"66b5d44e-a4a3-4e60-a594-5765cf2f9 cc7","producttime":"2012-05-31 07:42:04:861","sendtime":"2012-05-31 07:42:04:923 ","remaining":0}。 07:41:58:224 得到消息:{"id":563,"content":"d3e3828d-07be-4578-8129-009e44650 efe","producttime":"2012-05-31 07:42:05:375","sendtime":"2012-05-31 07:42:05:485 ","remaining":0}。 07:41:58:686 得到消息:{"id":564,"content":"ed7f9dfc-d0a9-433a-be33-89bf7c631 ce8","producttime":"2012-05-31 07:42:05:890","sendtime":"2012-05-31 07:42:05:937 ","remaining":0}。
当服务端有积压消息时:
09:22:52:507 得到消息:{"id":3435,"content":"65d862db-51e1-4ada-a936-1b5a92f0 462a","producttime":"2012-05-31 08:06:43:418","sendtime":"2012-05-31 09:22:56:37 1","remaining":8884}。 09:22:52:529 得到消息:{"id":3436,"content":"37e596b8-71b6-4a60-aa72-74b1497f dca1","producttime":"2012-05-31 08:06:43:933","sendtime":"2012-05-31 09:22:56:48 0","remaining":8883}。 09:22:52:751 得到消息:{"id":3437,"content":"30cab410-5866-4e1a-a8c6-5c3d682f 4f14","producttime":"2012-05-31 08:06:44:447","sendtime":"2012-05-31 09:22:56:59 0","remaining":8882}。 09:22:52:753 得到消息:{"id":3438,"content":"50dbde92-bc6d-42cb-9470-208c419b b788","producttime":"2012-05-31 08:06:44:962","sendtime":"2012-05-31 09:22:56:69 9","remaining":8881}。 09:22:53:036 得到消息:{"id":3439,"content":"3d52fda2-cce8-4db6-a4ac-4e8604e8 33e3","producttime":"2012-05-31 08:06:45:477","sendtime":"2012-05-31 09:22:56:82 4","remaining":8881}。 09:22:53:038 得到消息:{"id":3440,"content":"b27dfd02-41ce-4699-8398-9049e3ab 6789","producttime":"2012-05-31 08:06:45:992","sendtime":"2012-05-31 09:22:56:93 3","remaining":8880}。 09:22:53:041 得到消息:{"id":3441,"content":"1fc7b41b-4846-4874-a276-539607f6 f1fd","producttime":"2012-05-31 08:06:46:507","sendtime":"2012-05-31 09:22:57:04 2","remaining":8879}。 09:22:53:304 得到消息:{"id":3442,"content":"da1e8eb7-bef7-4f9c-8e08-4996fcd7 7713","producttime":"2012-05-31 08:06:47:021","sendtime":"2012-05-31 09:22:57:15 1","remaining":8878}。
id:服务端产生的消息编号
content:消息内容
producttime:消息产生时间
sendtime:消息发送时间
remaining:服务端积压消息数量
现在是500毫秒产生一条消息,100毫秒给推出去。
这中间还有一个问题,就是服务端与客户端的时间不一致,这个可能需要专门开发一个另外的程序用来校对时间,不用在这里面进行校对了。
如果有哪位朋友如果有兴趣一起开发的话,请联系我:ha666@ha666.com,热烈欢迎。
总结一下:总体来说,功能是实现了,不过运行过程中还是遇到了一些问题,这篇博文先暂停,修复以下问题后再继续写。
1、OutOfMemoryException
今天是8月8日,OutOfMemoryException的问题终于解决,消息推送系统继续测试和优化。
先上一段消息内容:
06:14:39:098 得到消息:{"id":1108,"content":"2012-08-09 06:14:44","producttime":"2012-08-09 06:14:39:052","sendtime":"2012-08-09 06:14:39:096","remaining":0}
这个结果是一段JSON格式的文本,客户端的处理有两种方式:
1、反序列化。
2、正则表达式提取。
两种方式对比,反序列化开发容易,但代码量较大,正则表达式开发难,但代码量小,最终决定,用正则表达式提取,来实现在客户端的数据提取。