Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

two-way communication in web services ?  RSS feed

 
esam kan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am starting out with web services. web services allow the client to sent the server a message and get a response. thus it is a message and response type of relationship. the client send one message , wait for the result and then get one response.
sometimes however i want my client and the server to send and receive data at real time e.g. for a real time game .the conversation between the client and the server could go on like so:


you got the idea. so what is the name of the technology(ies) used for that?

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Request and response. If that's not what you want, then you don't want a web service.
 
Ron McLeod
Saloon Keeper
Posts: 1600
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use Server-sent events. Browser support is included in HTML5 using EventSource. Have a look at the Stream Updates with Server-Sent Events article for a nexplanation of how it works and some code examples.

I have a web-based System Dashboard which is alerted to changes in the system state using SSE, triggering it to fetch an updated representation of the state and reflect the new state on the dashboard. Here is a real example:

Dashboard client subscribes to event stream
GET /event/manage HTTP/1.1
Host: 172.25.129.11:8080
Connection: keep-alive
Accept: text/event-stream
Cache-Control: no-cache
Origin: http://172.25.137.188
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36
Referer: http://172.25.137.188/bss/statusSummary.html
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-GB,en;q=0.8,en-US;q=0.6,es;q=0.4,fr;q=0.2,ja;q=0.2


Serrver responds indicating output will be chunked
HTTP/1.1 200 OK
Access-Control-Allow-Origin: http://172.25.137.188
Access-Control-Expose-Headers: Content-Type, Location, Link, Accept, Allow, X-Ssi-Debug-Info, X-Ssi-Resource-Identifier, Retry-After
Access-Control-Allow-Headers: Origin, Content-Type, Accept, X-Ssi-Role
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, PATCH, DELETE
Server: Platform Manager
Content-Type: text/event-stream
Date: Wed, 23 Sep 2015 16:34:11 GMT
Transfer-Encoding: chunked
HTTP/1.1 200 OK


Network cable gets plugged-in, link status change detected, event sent to dashboard client
event: state-change
data: {"subsystem":"platform","resource-type":"ethernet","resource-instance":"eth1","resource-identifier":"platform:ethernet:eth1","new-state":"UP"}

Dashboard link status indicator for eth1 goes green

DHCP exchange completes, event sent to dashboard client
event: state-change
data: {"subsystem":"platform","resource-type":"ethernet","resource-instance":"eth1","resource-identifier":"platform:ethernet:eth1","new-state":"DHCP_UPDATED"}


Client requests current state of network interface
GET /manage/platform/network/ethernet/eth1/network-state HTTP/1.1
Host: 172.25.129.11:8080
Connection: keep-alive
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36
Origin: http://172.25.137.188
Accept: */*
Referer: http://172.25.137.188/bss/statusSummary.html
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-GB,en;q=0.8,en-US;q=0.6,es;q=0.4,fr;q=0.2,ja;q=0.2


Web service sends response
HTTP/1.1 200 OK
X-Ssi-Resource-Identifier: platform:ethernet:eth1
Link: </metadata/view-for-update/network-state>; rel="metadata"; use-method="GET"
Access-Control-Allow-Origin: http://172.25.137.188
Access-Control-Expose-Headers: Content-Type, Location, Link, Accept, Allow, X-Ssi-Debug-Info, X-Ssi-Resource-Identifier, Retry-After
Access-Control-Allow-Headers: Origin, Content-Type, Accept, X-Ssi-Role
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: OPTIONS, HEAD, GET, POST, PUT, PATCH, DELETE
Server: Platform Manager
Content-Type: application/json
Date: Wed, 23 Sep 2015 16:14:27 GMT
Content-Length: 101
{"ip-address":"172.25.129.110","prefix":23,"state":"UP","mtu":1500,"mac-address":"00:0b:ab:61:75:be"}

Dashboard get updated with details for new network parameters for network interface
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66182
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
SSE assumes modern browsers, of course. It looks as if browser support has caught up quite a bit, but Microsoft, as usual, pokes a stick in the wheels.

Unless, as I do, you have the luxury of telling your customers to use a real browser and forgo support of IE (or any other browser that's not keeping up).
 
esam kan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much. that was brilliant information.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!