lilzz
Posts: 411
Joined: Sat Nov 30, 2013 5:27 pm

What Port Number I should use for Socket

Wed Jan 22, 2014 4:38 pm

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.

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: What Port Number I should use for Socket

Wed Jan 22, 2014 5:19 pm

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.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

Heater
Posts: 15950
Joined: Tue Jul 17, 2012 3:02 pm

Re: What Port Number I should use for Socket

Wed Jan 22, 2014 5:29 pm

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.
Memory in C++ is a leaky abstraction .

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: What Port Number I should use for Socket

Wed Jan 22, 2014 5:36 pm

Hi,
Heater wrote:This is not true for UDP.
Ups, you're right...


Thanks, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

User avatar
DougieLawson
Posts: 39124
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: What Port Number I should use for Socket

Wed Jan 22, 2014 5:36 pm

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.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

Return to “General discussion”