{"hidden":false,"children":[{"configs":{"itemId":"module"},"expanded":true,"children":[{"configs":{"layout":"fit","itemId":"viewport1"},"expanded":true,"children":[{"configs":{"layout":"fit","itemId":"panelMain"},"expanded":true,"children":[{"configs":{"itemId":"gridMain"},"expanded":true,"children":[{"configs":{"itemId":"tbar"},"expanded":true,"children":[{"configs":{"itemId":"sendMsg","text":"发送消息","iconCls":"comment_icon"},"expanded":false,"children":[],"type":"item","events":{"click":"say();"}},{"configs":{"itemId":"sendAjax","text":"服务器发送","iconCls":"execute_icon"},"expanded":false,"children":[],"type":"item","events":{"click":"$.ajax({\n    url:\"/agWebSocketControl/sendMsgFromJava\",   \n    async:true,//\n    data:{\n      id:'1111'\n    },    //参数值\n    type:\"POST\",   //请求方式\n    beforeSend:function(){\n       console.info('beforeSend');\n        //请求前的处理\n    },\n    success:function(req){\n      console.info('success');\n        //请求成功时处理\n    },\n    complete:function(){\n      console.info('complete');\n        //请求完成的处理\n    },\n    error:function(){\n        console.info('error');\n        //请求出错处理\n    }\n});\n"}},{"configs":{"itemId":"sendMsgWin","text":"发送消息(弹窗)","iconCls":"wait_icon"},"expanded":false,"children":[],"type":"item","events":{"click":" Wb.run({\n   url: 'm?xwl=websocketModel/msgWin',\n   contextOwner: app,\n   params: {\n     url: 'm?xwl=supcan/imBillHD/imbillHdView',\n     businessType:'进口换单'\n   },\n   success: function(appOld) {\n     var win = new Ext.window.Window(appOld._socketWin); //_window1为配置对象，window1为实例\n     win.show();\n   }\n });"}}],"type":"toolbar"},{"configs":{"itemId":"store"},"expanded":false,"children":[],"type":"store"},{"configs":{"itemId":"columns"},"expanded":true,"children":[{"configs":{"itemId":"column1"},"expanded":false,"children":[],"type":"column"}],"type":"array"}],"type":"grid"}],"type":"panel"}],"type":"viewport"}],"type":"module","events":{"finalize":"// 首先判断是否 支持 WebSocket\nif ('WebSocket' in window) {\n    console.log(\"此浏览器支持websocket\");\n    websocket = new WebSocket(\"ws://\"+document.location.host+\"/echo\");\n} else if ('MozWebSocket' in window) {\n   alert(\"此浏览器只支持MozWebSocket\");\n} else {\n    alert(\"此浏览器只支持SockJS\");\n}\n\n// 打开连接时\nwebsocket.onopen = function(evnt) {\n    console.log(\"  websocket.onopen  \");\n};\n\n// 收到消息时\nwebsocket.onmessage = function(evnt) {\n    alert(evnt.data);\n};\n\nwebsocket.onerror = function(evnt) {\n    console.log(\"  websocket.onerror  \");\n};\n\nwebsocket.onclose = function(evnt) {\n    console.log(\"  websocket.onclose  \");\n};\nfunction say() {\n    //客户端主动发消息\n    websocket.send('客户端数据');\n}"}}],"roles":{"default":1},"title":"握手与消息发送","iconCls":"console_icon","inframe":false,"pageLink":""}