Page 1 of 1

What Port Number I should use for Socket

Posted: Wed Jan 22, 2014 4:38 pm
by lilzz
Hi,
I created a socket on the pi and try to send out UDP broadcast package. Currently I using port number 3400. i used a packet analyzer to check if packets are being send out from the Pi thru wifi.
But nothing come out from the Pi.

Make me wonder what port number I should use for pi.

Re: What Port Number I should use for Socket

Posted: Wed Jan 22, 2014 5:19 pm
by FLYFISH TECHNOLOGIES
Hi,
lilzz wrote:I created a socket on the pi and try to send out UDP broadcast package.
To whom ?
Sockets need to be connected, then you can broadcast to peers.

I have doubts that this is port number-related issue you're facing. Take some server and client code, run it, establish connection and then analyze traffic...


Best wishes, Ivan Zilic.

Re: What Port Number I should use for Socket

Posted: Wed Jan 22, 2014 5:29 pm
by Heater
FLYFISH TECHNOLOGIES.
Sockets need to be connected, then you can broadcast to peers.
This is not true for UDP.

TCP/IP sockets need a connection, client to server. UDP does not have an idea of a connection, it can just send packets.

One can use port numbers above 1024 (Is it that exact number, I forget?) without being root. So 3400 should be OK.

Here is an example of sending UDP packets in JavaScript for node.js:

Code: Select all

var dgram = require('dgram');
var message = new Buffer("Some bytes");
var client = dgram.createSocket("udp4");
client.send(message, 0, message.length, 41234, "localhost", function(err, bytes) {
  client.close();
});
I'm not really familiar with broadcasting.

Re: What Port Number I should use for Socket

Posted: Wed Jan 22, 2014 5:36 pm
by FLYFISH TECHNOLOGIES
Hi,
Heater wrote:This is not true for UDP.
Ups, you're right...


Thanks, Ivan Zilic.

Re: What Port Number I should use for Socket

Posted: Wed Jan 22, 2014 5:36 pm
by DougieLawson
Ports between 1 & 1023 are reserved for tasks running with elevated privileges.

Ports 1024 to 65535 are available for any usage ( give or take that ones like 8080, 8443, 5901-59xx, 3306 are used for some predefined purposes).

Using 3400 for your code is a good choice. I usually use 1337 for testing stuff.

Use
sudo tcpdump eth0 -w /tmp/TCP.eth0.dump &
To get a trace.

If you copy that file to windows you can use Wireshark to analyse it.

In your application test the return value from every UDP service call for success or failure.