This repository has been archived by the owner on May 4, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a13584b
commit dc3b80a
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
|
||
typedef enum { | ||
TCP = 0, | ||
UDP, | ||
PIPE | ||
} stream_type; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dc3b80a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this will be seen, but it's worth a question.
Isn't the process:
??
In this test the recv_start happens immediately after init without an open or bind. So then what's the point of open and bind?
dc3b80a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DavidJFelix uv_udp_open() is for using a file descriptor you control, uv_udp_bind() for binding to a specific address and port. If you don't call uv_udp_bind() first, the operating system will do an implicit bind to the 'any address' with a random port. You can also do an explicit bind to a random port by specifying 0 as the port number, by the way.
dc3b80a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the quick response. This makes some sense, but I'm still not clear on why the bind is unneeded in this test. Doesn't the implied client need to know which port to send it's message to on the server? I'm not trying to imply that the test is incorrect in anyway, I'm just using it and the libuv tutorials as models and this was an inconsistency I noted between the two.
dc3b80a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The server's recv callback gets a struct sockaddr that contains the address and the port of the sender. If you look at line 197, you can see how the server basically bounces back the message to the sender.
dc3b80a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand how the server gets the client's port, but how does the client get the server's port:
So in theory, an echo server should always bind (or at least check what it's port is so that clients can be told which port it is operating on). Is this a correct assumption on my part?
dc3b80a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to be reachable at a well-known address/port (e.g. 0.0.0.0:53 for a DNS server), then yes: you must call uv_udp_bind().
dc3b80a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks for your help and writing this in the first place. I wouldn't be nearly as far into my project without it.