I'm getting started with freeDiameter. I have gone through docs over and over but didn't find any configuration variable to set the source port for when connection as a client.
My goal is to connect to HSS which requires the source port of my outgoing SCTP to be 3893 and destination port to be 3868.
Is there any configuration variable that I've missed?
We can only configure the server side port in 'freediameter'.
when we create a client socket,system will assign a port as source port.
if u want to specify the portof client,u should use bind() to bind the port(3893) with u client socket.
Related
I have a Server socket and a device which uses TCP long-connection mode.
They can connect and exchange data together. The node.js server is something like this:
net.createServer(function (socket) {
console.log('ip:port' + socket.remoteAddress +':'+ socket.remotePort);
socket.on('data', console.log);
}).listen(‘0.0.0.0’, 8888);
The device connects just right and I'm able to receive data from it.
I can send commands to it by using the same process, by just doing socket.write('dothisplease') and this works too.
Now I have another worker process which should be sending commands at regular intervals. I can get ip and port from console.log when the device connects, it looks like: xx.xxx.xx.xxx:63024
I tried using this combination ip:port to create new connection:
var client = new net.Socket();
client.connect(device_port, device_ip, function () {
client.write('dothisplease');
});
... but the result was ECONNREFUSED
Is it right to use the same port to create a second connection to the device?
Why does it work from the same process, but does not work from another?
Eventually, can I pass the socket to another node Worker process. How?
Thanks a lot!
Your server is listening on port 8888. That's the port that all clients need to connect to. The client will also have to know what the server's IP address is in order to connect to it. A client uses a target IP address and target port to specify the destination for a TCP connection.
socket.remotePort is not the port that anyone can connect on. That is the outgoing port that the first client used to connect to your server port. The outgoing port is a client bookkeeping thing that helps the client keep track of which network traffic belongs to which socket and is usually randomly assigned by the client.
You read more about what remotePort is here.
For reference, a TCP connection consists of two endpoints and each endpoint has an IP address and a port. The server will need to have a known IP address and a known port that all clients will use in order to connect to it. The client will already have its own IP address. Then, during the process of making a TCP connection to a server, the client will dynamically allocate an unused port number for the communication for this socket. That port number is used by the client to keep track of which network traffic belongs to which socket. This is not a port number that anyone can connect to.
Is it right to use the same port to create a second connection to the device?
No. You can't create a connection to a client. You can only create a connection to a listening server. And, you couldn't use the client's port that belongs to that other socket either.
I created tcp connection between client and server using nodejs (net module). Server is listening on already predefined port and client is connecting to that port.
As far as i understand port for client is dynamically assigned by node? Is that correct?
What kind of algorithm node is using to assign "random" port for the client? How this works, is this determined by node or by OS?
Is it possible to define static port which client is going to use? Is it possible to define range of ports for the client to use?
NOTE: I think i found discussion/question with similar subject on stackoverflow before, but i cannot find it anymore. I would apprecaite if you can share any reliable resources regarding this subject.
The source port number is usually pretty much irrelevant to your programming unless you have a router or firewall that is somehow restrictive in that regard. It is merely used by the underlying TCP infrastructure to keep track of different TCP connections.
From this article:
A TCP/IP connection is identified by a four element tuple: {source IP,
source port, destination IP, destination port}. To establish a TCP/IP
connection only a destination IP and port number are needed, the
operating system automatically selects source IP and port.
The above referenced article describes how Linux selects the source port number.
As to your particular questions:
What kind of algorithm node is using to assign "random" port for the
client? How this works, is this determined by node or by OS?
It is determined by the OS. That source port number is selected by the originating host at the TCP level before the connection is even made to node.js.
Some other reference articles:
Does the TCP source port have to be unique per host?
how can an application use port 80/HTTP without conflicting with browsers?
Note: there is no security reason I'm aware of for a firewall to limit the source port number or block certain source port numbers. They are a TCP bookkeeping number only, not related at all to security or the type of service being used. Note, this is different than the destination port which is usually correlated directly with the type of service being used (e.g. 80 is HTTP, 25 is SMTP, 143 is IMAP, etc... When you make a TCP connection to a different host, you specify the host address and the destination port number. You don't specify the source port number.
The selected answer is provides a lot of info, but does not deal with the underlying problem. Node does not appear to allow https.request to specify a port for the client. There exist localAddress and localPort options, but they appear to be broken.
I've opened a new question on this issue. Hopefully someone will answer with something other than "just don't do that."
Is there a way to set the source port for a node js https request?
I need to create TCP socket with specific source (local) port. For example, socket from my PC (192.168.1.2:7777) to server (192.168.1.3:7778). Why i see now is that node.js allows only random source port.
What is the way to do this?
When you do not specify a port in the io.connect() function on the client side, what port does the client listen to?
eg:
var socket = io.connect('http://example.com/'); // listening to port 80?
The reason I ask is because I deployed the server side of this application on heroku. The front end is an IOS application. The objective C socketIO library I'm using for the front end (https://github.com/pkyeck/socket.IO-objc) requires me to specify a port. But I'm not sure what port I should listen to since this is not static on the server side.
I wrote client program in javascript for testing and it works when I do not specify a port.
Any help would be much appreciated.
It listens on the port the server listens to. Imagine you set your server to listen port 8080. Then you load your page at http://localhost:8080 and the server returns the page which contains the socket related JS code.
If you don't specify any port or host as in var socket = io.connect();, it defaults to the host and port of the current page.
If you specify only the host which is same as the current host, it defaults to the port of the current host.
If you specify only the host which is different from the current host, it defaults to port 80 if the protocol is HTTP. If the protocol is HTTPS, then the port defaults to 443.
Here is the related code for url.js parser.
I'm using getaddrinfo in my socket programming in linux. I have created a client and a server. Currently the client has a hardcoded static port number. Everything works fine.
But I want the system to dynamically assign a port number to the client whenever it connects to the server. How do I do this using getaddrinfo?
I'm using a TCP socket.
Just don't call bind before calling connect and the TCP stack will assign the client a "random" source port. If you need to know what port you're connecting from (and you usually don't), you can call getsockaddr after calling connect.
Alternatively, can call bind specifying port 0. In that case, again, the stack will assign the client a "random" unused source port to connect from. This option would be preferred if you don't want to special case allowing the implementation to select the port or if you need to specify the local IP address for some reason.