Comments (5)
Hi! If I'm understanding you correctly, you don't know how to send the reply back to the original sender of the data inside the handle_data/2
, right?
That function expects you reply with {ok, [response()], State}
, where response()
is {external_request_id(), term()}
. This means that you have to return whatever request identifier you used to originally send your message to the server.
Check out an example with the arithmetic_tcp_client
module under the test folder:
shackle/test/arithmetic_tcp_client.erl
Lines 103 to 112 in f92c2e1
The client creates a new request id, and generates a new message with it:
shackle/test/arithmetic_protocol.erl
Lines 34 to 37 in f92c2e1
As you can see, the original request id is part of the binary we send to the server, which should reply back with the id so that the client can re-use it:
shackle/test/arithmetic_tcp_client.erl
Lines 89 to 98 in f92c2e1
Inside parse_replies
, we extract the request identifier from the server message:
shackle/test/arithmetic_protocol.erl
Lines 45 to 48 in f92c2e1
As such, when arithmetic_tcp_client:handle_data/2
returns, the pool is able to match the original request id to the original sender, and return it.
Hope this helps!
from shackle.
hi.
thanks very much for the help and sorry for late reply.
thanks for the samples and its shed a lot of light on how the library works.
from our end whats happening is that the processes themselves are the direct connection between themselves and the tcp server.
there is no client sending a message with shackle acting as sort of a proxy.
i think thats the major difference.
so the thing is that when the shackle process gets the data,it just processes it and sends it back if necessary.
so i was confused because there is no way to know how to send data directly to the requesting party.
thanks!!
from shackle.
You can still use shackle without a request_id() if your response are in order. All you have to do it keep a counter of requests out and requests in.
from shackle.
please can u give me an example of that.
there is an example you cited above containing the counter but that also contains the request id.
from shackle.
You need to keep two counters (one for requests out and one for requests in).
See https://github.com/lpgauth/buoy/blob/master/src/buoy_client.erl
from shackle.
Related Issues (20)
- Shackle 0.6.6 crashes on OTP-21 because `persistent_term:get/2` is undefined.
- DRY shackle_server_{SSL|TCP|UDP}
- Idea: support custom fun execution after handle_data
- Support send and forget messages? HOT 7
- Idea: evaluate the use of decentralized_counters for ETS HOT 1
- ARM build fails HOT 2
- connection closed messages are spamming the logs HOT 3
- Request does not timeout when client throws an error HOT 4
- Make client name configurable
- Add `max_requests` client option HOT 3
- shackle on CentOS 6, tcp data lose HOT 4
- Export type `request_id` HOT 1
- update hex package to 0.5.3 HOT 3
- Support `ssl_closed`
- master failure ets table HOT 2
- Add options to shackle cast/call to not store request HOT 1
- Any plan to add metrics for the pools ? HOT 2
- Validate timeout value > 0
- ETS_TAKE being defined despite using OTP 17 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shackle.