Zato 3 Websockets documentation and examples


I’m currently experimenting with Zato 3.0 Websockets. I’ve found a high-level design post at

Is there any documentation explaining how to create sample services for websockets and are there any examples available with client implemenation?


Hi @umesh,

WebSockets are just a type of an input channel like REST, AMQP or other types.

This means that there is nothing special in terms of creating services for WebSockets as opposed to (say) REST ones - you can just take any existing usage example from the documentation, mount it on a WebSockets channel and it will just work.

Naturally, you won’t have access to things that are specific to other protocols - e.g. metadata specific to other protocols won’t exist in WebSockets. But other than that, the whole magic of Zato is that you can take the same business service and swap underlying communications channels with ease.

As for the client implementation - there is a project on PyPI that does just that:

All of this will be properly documented for 3.0, but you can already check a usage example in there - look up client.invoke at the bottom of the main Python source code file.

1 Like

Hi @dsuch,

Thanks for the client example.

I was testing with the example provided and when I try to connect to websocket the connection is established properly. But when I send a message to the socket, it is throwing below warning and because of the warning service is not invoked

2017-09-07 03:05:40,891 - INFO - 15120:DummyThread-31 - zato_web_socket:441 - Request received cid:311a65be785d8d833d84d314, client:ws.9c3079bd77d4d2ec04e19412
2017-09-07 03:05:40,892 - WARNING - 15120:DummyThread-31 - zato_web_socket:469 - Traceback (most recent call last):
File “/root/zato/code/zato-server/src/zato/server/connection/web_socket/”, line 464, in _received_message
self.handle_create_session(cid, request)
File “/root/zato/code/zato-server/src/zato/server/connection/web_socket/”, line 330, in handle_create_session
File “/root/zato/code/zato-server/src/zato/server/connection/web_socket/”, line 309, in register_auth_client
}, needs_response=True)
File “/root/zato/code/zato-server/src/zato/server/connection/web_socket/”, line 360, in invoke_service
’peer_host’: self._peer_host,
AttributeError: ‘WebSocket’ object has no attribute '_peer_host’
2017-09-07 03:06:36,947 - INFO - 15120:DummyThread-30 - zato_web_socket:472 - Received message '{“meta”: {“timestamp”: “2017-09-06T13:25:47.348718”, “client_name”: “My Client”, “token”: “ws.token.aec3a756d53b84a878d6e269”, “client_id”: “32351b3f5d16”, “action”: “invoke-service”, “id”: “”}, “data”: {“service”: “”}}'
2017-09-07 03:06:36,948 - INFO - 15120:DummyThread-37 - zato_web_socket:441 - Request received cid:47ad499ebcf11776213c09ad, client:ws.9c3079bd77d4d2ec04e19412
2017-09-07 03:06:36,948 - WARNING - 15120:DummyThread-37 - zato_web_socket:382 - Service could not be invoked, cid:47ad499ebcf11776213c09ad, e:Traceback (most recent call last): File "/root/zato/code/zato-server/src/zato/server/connection/web_socket/", line 378, in _handle_invoke_service service_response = self.invoke_service(cid, self.config.service_name, File "/root/zato/code/zato-server/src/zato/server/connection/web_socket/", line 360, in invoke_service 'peer_host': self._peer_h ost,AttributeError: 'WebSocket' object has no attribute '_peer_h ost'
2017-09-07 03:06:36,949 - INFO - 15120:DummyThread-37 - zato_web_socket:398 - Sending response {“meta”:{“status”:500,“timestamp”:“2017-09-07T03:06:36.949188”,“in_reply_to”:“”,“id”:“”,“error_message”:“Could not invoke service,, cid:47ad499ebcf11776213c09ad”},“data”:{“cid”:“47ad499ebcf11776213c09ad”}}
2017-09-07 03:06:36,949 - INFO - 15120:DummyThread-37 - zato_web_socket:466 - Response returned cid:47ad499ebcf11776213c09ad, time:0:00:00.001041

The server is trying to get the hostname using

#inside "/zato/server/connection/web_socket/" :: line 121
self._peer_host = socket.gethostbyaddr(_peer_address[0])[0]

If the host address is not returned _peer_host is not set and because of this an error is thrown at line::361

#while invoking the service line::361
'peer_host': self._peer_host,

When I add the host address of my client inside the hosts file (/etc/hosts), it is working fine. But I can’t have all the client addresses in host file. It seems to me like _peer_host should also have default value similar to _peer_fqdn.

Is there a way to get around this?


This is interesting - what value does _peer_address have on this system?