On 23 Nov 2012, at 03:06, "[email protected]"
<[email protected]> wrote:
> Dears,
> My PC environment are windows XP professional Version 2002 Service Pack 3,
> JDK1.6, Tomcat7.0.30.
> my Java web project is an internet online chat-room based on websocket. I run
> the local-host service in Tomcat and then connect my chat-room in chrome,
> if the connection between server and browser is OK, the websocket client side
> function onopen() will pop up a message "open".
> But, the point is if I open several pages at same time, I can see all of
> pages pop up the message "open", it means every connection of page to server
> is OK.
> but when I try to send some words to server, The server has no response ( in
> the other word, the server side function onTextMessage() is not called),
> it happen in part of the pages not all of them. I would like to know if you
> encounter the same problem.
> Excuse me, the second question: how to set the maximum idle time of
> connection of websocket.
> The set up in server.xml does not work:
> <Connector port="8080" protocol="HTTP/1.1"
> connectionTimeout="5000"
> redirectPort="8443" />
> <!-- A "Connector" using the shared thread pool-->
> <!--
> <Connector executor="tomcatThreadPool"
> port="8080" protocol="HTTP/1.1"
> connectionTimeout="5000"
> redirectPort="8443" />
> -->
>
>
> These is part of the client side code:
> function startWebSocket() {
> if ('WebSocket' in window)
> {ws = new WebSocket("ws://localhost:8080/MyWebSocket/mywebsocket.do");
> }
> else if ('MozWebSocket' in window)
> {ws = new
> MozWebSocket("ws://localhost:8080/MyWebSocket/mywebsocket.do");
> }
> else
> alert("not support");
>
> ws.onmessage = function(evt) {
> alert(evt.data);
> };
> ws.onopen = function(evt) {
> alert("open");
> };
> ws.onclose = function(evt) {
> alert("close");
> };
>
> }
How have you configured the WebSocket Servlet?
p
> And part of the server side code:
> public class MyMessageInbound extends MessageInbound {
>
> @Override
> protected void onBinaryMessage(ByteBuffer arg0) throws IOException {
> // TODO Auto-generated method stub
>
> }
>
> @Override
> protected void onTextMessage(CharBuffer msg) throws IOException {
> System.out.println(msg.toString());
> for (MessageInbound messageInbound : InitServlet.getSocketList()) {
> WsOutbound outbound = messageInbound.getWsOutbound();
> CharBuffer buffer = CharBuffer.wrap(msg);
> outbound.writeTextMessage(buffer);
> outbound.flush();
> }
> }
>
> @Override
> protected void onClose(int status) {
> InitServlet.getSocketList().remove(this);
> super.onClose(status);
> System.out.println(getTime()+" connection is closed");
> }
>
> @Override
> protected void onOpen(WsOutbound outbound) {
> super.onOpen(outbound);
> InitServlet.getSocketList().add(this);
> System.out.println(getTime()+" connection is open");
> }
>
> public String getTime(){
> Date now = new Date();
> SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd
> HH:mm:ss");
> String NowTime = dateFormat.format( now );
> return NowTime;
> }
>
> }
>
> I would eagerly look forward to your reply.
> **********************************************************************************************************************************************
> This e-mail is confidential for WistronITS corp. It may be legally
> privileged. If you are not the Addressee you may not copy,
> forward, disclose or use any part of it. If you have received this message in
> error, please delete it and all copies from your
> system and notify the sender immediately by return e-mail.Internet
> communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
> ***********************************************************************************************************************************************
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]