Comments (6)
You can allocate a listener, and then set the NNG_OPT_LOCADDR on it. That can specify a complete address -- including the TCP port number.
from nng.
I want to specify dialer's port, should I set NNG_OPT_LOCADDR on listener?
from nng.
In reqrep demo, I call nng_dialer_get_addr
in client's every loop, but the sa_addr and sa_port different from every call. Is this OK?
And how to decode the address? for example, sa_addr = 2123998088
while (1) {
printf("CLIENT: SENDING DATE REQUEST\n");
if ((rv = nng_send(sock, cmd, sizeof(cmd), 0)) != 0) {
fatal("nng_send", rv);
}
if ((rv = nng_recv(sock, &buf, &sz, NNG_FLAG_ALLOC)) != 0) {
fatal("nng_recv", rv);
}
if (sz == sizeof(uint64_t)) {
uint64_t now;
GET64(buf, now);
printf("CLIENT: RECEIVED DATE: ");
showdate((time_t) now);
} else {
printf("CLIENT: GOT WRONG SIZE!\n");
}
nng_msleep(sleep);
sleep++;
if (sleep == 4) {
sleep = 4000;
}
nng_sockaddr addr;
nng_dialer_get_addr(dialer, NNG_OPT_LOCADDR, &addr);
printf("%d, %d\n", addr.s_in.sa_port, addr.s_in.sa_addr);
}
from nng.
@gdamore any suggestion ?
from nng.
The documentation should indicate properly that the option for NNG_OPT_LOCADDR is an nng_sockaddr. However, be advised that the port numbers are in network byte order, not host byte order. For sa_addr, you're looking at the network byte order IP v4 address - so:
126.153.163.136
This is standard BSD socket practice.
When you call dial, by default you'll get a unique local address -- because that's the way TCP works. You can request a specific source address, but that requires you set that option on the dialer. Note that doing so will impair automatic redialing if the connection is lost, and will prevent being able to establish multiple outbound connections so I don't recommend it unless you have no choice and you know exactly what you're doing (which doesn't seem to be the case here.)
from nng.
Related Issues (20)
- Android gradle builds are failing while trying to use libnng.a HOT 1
- TLS test failures
- Define NNG_EXPIRE_THREADS not set in CMakeLists.txt HOT 3
- nng_aio_result return 0 but nng_aio_get_msg return NULL msg HOT 2
- Warning when building with NDEBUG HOT 3
- [Question] Server (rep) keep receiving same data HOT 1
- Throw NNG_EADDRINUSE but cannot find which process HOT 2
- nngcat server cannot support more than 1.2K nngcat clients HOT 9
- Limits (restrictions) for PUB/SUB protocol HOT 1
- [question] How to run the server normally when running in REQ mode? HOT 3
- NNG Socket Concept and Endpoints HOT 1
- NNG Architecture and Constraints HOT 1
- NNG Port to Other Languages HOT 3
- cmake find_package fails due to too restrictive permissions of /usr/local/lib64/cmake directory HOT 4
- NNG fails in child process created using fork() HOT 2
- Demo application will not link demo application under windows, with nng.lib built as static library HOT 3
- nng_dial for sub0 called synchronously is returning before the socket is ready to receive messages HOT 6
- Can NNG be used for LAN service discovery? HOT 3
- Q: Does nng has 'Too many open files' quesion? HOT 5
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 nng.