Question

I am using GraniteDS Gravity for my messaging service. My application works fine when using data polling, however when I try to use websocket channel instead of data polling, messages could not reach to clients. I have also tried to modify sample Gravity chat application created by Eclipse GraniteDS plugin to work with websocket channels, but it didn't work too.

I'm using Tomcat 7.0.39

To make easier to reproduce the case, I have listed the changes I've made to chat application created by GraniteDS plugin of Eclipse.

In web.xml

1) Modified servlet class:

old:org.granite.gravity.servlet3.GravityAsyncServlet

new:org.granite.gravity.tomcat.TomcatWebSocketServlet

2) Modified url pattern of servlet mapping

old:/gravityamf/*

new:/websocketamf/*

3) Added flash policy listener:

<listener>
    <listener-class>org.granite.gravity.websocket.PolicyFileServerListener</listener-class>
</listener>

<context-param>
    <param-name>flashPolicyFileServer-allowDomains</param-name>
    <param-value>*:*</param-value>
</context-param>

In services-config.xml

1) Updated channel-definition

old:

<channel-definition
    id="gravityamf"
    class="org.granite.gravity.channels.GravityChannel">
    <endpoint
        uri="http://{server.name}:{server.port}/{context.root}/gravityamf/amf"
        class="flex.messaging.endpoints.AMFEndpoint"/>
</channel-definition>

new:

<channel-definition 
    id="gravityamf"
    class="org.granite.gravity.channels.WebSocketChannel">
    <endpoint
        uri="http://{server.name}:{server.port}/{context.root}/websocketamf/amf"
        class="flex.messaging.endpoints.AMFEndpoint" />
</channel-definition>

I have not changed the flex client. When I started the application, Tomcat prints the log "Gravity successfully started". But the messages send by producer do not reach the consumer.

What may be the problem ? Am I missing something in configuration?

Thanks.

Was it helpful?

Solution

After 4 days of struggling with the code, I've found the cause of the problem. First I discovered error message while debugging the producer.send() message on client side. It is throwing the following exception, while trying to connect socket

"cannot connect to Web Socket server at 
 http://localhost:8080/gravityTest/websocketamf/amf
(IoError: Error #2031: Socket Error. URL: localhost)"

but the thrown exception is not reaching to top level so I could not get any idea about the exception for a long time.

After googling the exception, I find out that it is caused by flash security policy. Then I debugged the PolicyFileServerListener and find out that localAddress of the policy server after binding is [/0:0:0:0:0:0:0:0:843] because it is using InetSocketAddressIPv6. I guess this is the default behaviour of JDK 1.7. When I change the version of JDK to 1.6, localAddress became [/0.0.0.0:843]. After this change, my application succesfully accessed the policy server, and messaging with websocket worked fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top