multithreading – How to use UDP MulticastSocket for Reception with ThreadHandler-Looper-Handler in Android

I am trying to find the right architecture to be able to listen to UDP Multicast socket, receive the datagram packet that is in JSON format and then send the data to my BroadCast Receiver. It is important that the UDP must always listen and store packets even when the application is minimized.

My current approach is to use a ThreadHandler and have the socket listen and interpret the packet within the method run(). However, to keep the socket alive and keep listening i am passing this reference as a runnable within the run method to keep it looping which I believe is a wrong practice.

So, what would be the “right” approach, in the context of using a Thread/ThreadHandler/Looper/Handler and what methods should be overridden?

Should I use a looper with onLooperPrepared() doing the setup of socket etc and then do all the work in run()? Maybe just use handler to pass simple messages in the MessageQueue and use handleMessage() to interpret messages and send to BroadcastReceiver?

Thank your for your time.

UDP multicasting working properly in Dart(Linux) but not in Flutter(Android Emulator)

I am trying to make a service discovery for my app, So I tried it first in Dart and it worked. When I built it on flutter, it doesnt work properly. I have acquired the wifimulticastlock through platform channels in flutter and also have given permissions for it in the android manifest.

This is the service advertiser:

import 'dart:async';
import 'dart:io'
    show RawDatagramSocket, RawSocketEvent, InternetAddress, Datagram;
import 'dart:convert' show utf8;
import 'dart:async' show Timer;

main() {
  RawDatagramSocket dsocket;
  RawDatagramSocket.bind(InternetAddress.anyIPv4, 0).then((datagramSocket) {
    dsocket = datagramSocket;
    datagramSocket.broadcastEnabled = true;
    datagramSocket.readEventsEnabled = true;
    datagramSocket.listen((RawSocketEvent event) {
      if (event == RawSocketEvent.read) {
        Datagram datagram = datagramSocket.receive();
        if (datagram != null) {
          print('${datagram.address}:${datagram.port} -- ${utf8.decode(datagram.data)}');
          //datagramSocket.close();
        }
      }
    });
  });
  Timer.periodic(Duration(seconds: 1), (timer) {
    if(timer.isActive){
      dsocket.send("io.app.service".codeUnits, InternetAddress("224.0.0.1"), 8000);
    }
  });
}

This is my service discoverer:

import 'dart:io'
    show RawDatagramSocket, RawSocketEvent, InternetAddress, Datagram;
import 'dart:convert' show utf8;

main() =>
RawDatagramSocket.bind(InternetAddress.anyIPv4, 8000)
    .then((datagramSocket) {
  datagramSocket.readEventsEnabled = true;
  datagramSocket.joinMulticast(InternetAddress("224.0.0.1"));
  datagramSocket.listen((RawSocketEvent event) {
    if (event == RawSocketEvent.read) {
      Datagram datagram = datagramSocket.receive();
      if ((datagram != null)&&(utf8.decode(datagram.data)=="io.app.service")) {
        datagramSocket.send(datagram.data, datagram.address, datagram.port);
        print('${datagram.address}:${datagram.port} -- ${utf8.decode(datagram.data)}');
      }
    }
  });
});

This works when i run both in dart. This also works when I run the advertiser on Flutter and the discoveror on Dart. This doesnt work any other way.

Also the discoveror on dart doesnt detect the advertisers from external android devices in the same LAN.

Any help would be much appreciated.

http – creationg of udp server with client (c++)

I want to make a “simple Skype”, or something like that (with c++). So, I must create a web UDP server. I’ll capture webcam video using openCV and I need to send that data to a server that will resend it to a client. Moreover, I’d like to place that server “in a web”.
So, there’re a question(s):
-shall I use http?
-what libraries are better?
-what topics must I learn to understand that?

computer networks – Why processes on the internet are not required to use TCP or UDP?

Here is an excerpt from Andrew S. Tanenbaum, Computer Networks, 5th edition, Chapter 5 (The Network layer), Page 455:

(Fifth, processes on the Internet are not required to use TCP or UDP. If a user on machine A decides to use some new transport protocol to talk to a user on machine B (for example, for a multimedia application), introduction of a NAT box will cause the application to fail because the NAT box will not be able to locate the TCP Source port correctly.)

My question is in this context what does processes means? Is it a process of data exchange between routers? And why processes on the internet are not required to use TCP or UDP? Isn’t it apart of IP protocol and thus it will be used on the internet?

ipsec – Why IKEv2 uses UDP and not TCP?

As per the IKEv2 RFC 7296, it is a reliable protocol.

Since UDP is a datagram (unreliable) protocol, IKE includes in its
definition recovery from transmission errors, including packet loss,
packet replay, and packet forgery.

Furthermore, it also has retransmission timers (Section 2.1), sequence numbers in the form of message id (Section 2.2) and window size (Section 2.3). Although, the RFC clearly mentions that the purpose of window size is not to achieve congestion control.

The window size is normally a (possibly configurable) property of a
particular implementation, and is not related to congestion control
(unlike the window size in TCP, for example).

The question that I have is that why does IKEv2 uses UDP, and not leverage TCP instead?

firewall – UDP connection i/o timeout while port is reachable

on one server we encountered an issue where all kinds of UDP connections are failing. The same application and tests work on other servers with the same OS and similar setup.

nc -vz -u 83.61.**.** 7092
Connection to 83.61.**.** 7092 port [udp/*] succeeded!

With the go app:

read udp 5.9.**.**:49696->83.61.**.**:7092: i/o timeout

We tested it with a php and golang app.

We have tried it with a fully disabled firewall as well.

What could be the cause if netcat succeeds but other applications can’t.

Display delta timestamp and UDP data payload with tcpdump

I have a 1.5Gb capture of small UDP packets that I would like to turn into a CSV with just timestamp and UDP payload data in hex format.

An example of the desired output would be as follows:

% head Data3.txt 
0.000000,0000000041000000005ec812ac00047dce00000000
0.000194,0000000042000000005ec812ac00047db500000000
0.000227,0000000041000000005ec812ac00047dce00000000
0.000619,0000000042000000005ec812ac00047db500000000
0.000663,0000000041000000005ec812ac00047dce00000000
0.000854,0000000042000000005ec812ac00047db500000000
0.000883,0000000041000000005ec812ac00047dce00000000

I do not need this exact format, just a format that can later be transformed into this data.
The main point is having the HEX data sequence as in the above listing (in this case they are 21 bytes length UDP packets).

I am struggling to achieve this with tcpdump without success, the closest thing I have managed to get is:

% tcpdump -r May31Jun5.CME.ES.M20.pcap -x | more
00:00:00.231921 IP localhost.37281 > localhost.10000: UDP, length 21
        0x0000:  4500 0031 190b 4000 4011 23af 7f00 0001
        0x0010:  7f00 0001 91a1 2710 001d fe30 0000 0000
        0x0020:  4100 0000 005e d428 df00 049f 7f00 0000
        0x0030:  00
00:00:00.232037 IP localhost.37281 > localhost.10000: UDP, length 21
        0x0000:  4500 0031 190c 4000 4011 23ae 7f00 0001
        0x0010:  7f00 0001 91a1 2710 001d fe30 0000 0000
        0x0020:  4200 0000 005e d428 df00 049f 7f00 0000
        0x0030:  00
00:00:00.242870 IP localhost.37281 > localhost.10000: UDP, length 21
        0x0000:  4500 0031 1912 4000 4011 23a8 7f00 0001
        0x0010:  7f00 0001 91a1 2710 001d fe30 0000 0000
        0x0020:  4100 0000 005e d428 e000 049f 7f00 0000
        0x0030:  00

I would like to avoid Wireshark if possible, as the file is quite large and wireshark seems to fail and terminate itself.

Any tip is welcomed, both for the timestamp and the payload/data.

firewall – Allowing access to UDP range port in ipfw/FreeBSD

I have prepared the following configuration:

# cat /etc/firewall.conf 
add 1000 count udp from any to me 10000
add 1001 count udp from any to me 10001
add 1002 count udp from any to me 10002
add 65000 allow ip from any to any

This is the output from ipfw:

# ipfw list
00100 allow ip from any to any via lo0
00200 deny ip from any to 127.0.0.0/8
00300 deny ip from 127.0.0.0/8 to any
00400 deny ip from any to ::1
00500 deny ip from ::1 to any
00600 allow ipv6-icmp from :: to ff02::/16
00700 allow ipv6-icmp from fe80::/10 to fe80::/10
00800 allow ipv6-icmp from fe80::/10 to ff02::/16
00900 allow ipv6-icmp from any to any icmp6types 1
01000 allow ipv6-icmp from any to any icmp6types 2,135,136
01000 count udp from any to me 10000
01001 count udp from any to me 10001
01002 count udp from any to me 10002
65000 allow ip from any to any
65535 deny ip from any to any

I have the following two questions:

  1. What would be the command to allow UDP traffic from IP 203.0.113.1 to UDP port range 20500-20750? Would the rule below be the right one?

    add 2000 allow udp from 203.0.113.1 to me 20500-20750

  2. With the above configuration, do I ensure that all traffic is allowed?

OVH UDP 53 Problem | Web Hosting Talk


Hello,

I have the server in OVH, UK location. When my server gets attacked, ddos protection comes into play immediately. No problem so far.

But my server’s DNS access is lost. I allowed port 53 from the OVH Panel. But it did not provide a solution. OVH still has not been able to offer a solution to this issue.

Are there friends with similar problems?