how config aeron channel by udp multicast, all subs can receive messages? - multicast

I am trying to run a Basic Publisher/Subscriber pair on the same Multicast/Port.
I want to know how config channel for udp multicast, special the "interface" paramter, all subs can receive messages from pub?
I have three matchines, I want to test aeron by udp multicast type,
three matchines in one local network(lan),
pub matchineA ip 192.168.31.100,
sub1 matchineB ip 192.168.31.120,
sub2 matchineC ip 192.168.31.121,
my test case is:
pub: final String channel = "aeron:udp?endpoint=192.168.31.120:40456|interface=192.168.31.0/24|ttl=16";
sub1: final String channel = "aeron:udp?endpoint=192.168.31.120:40456|interface=192.168.31.0/24|ttl=16";
sub2: final String channel = "aeron:udp?endpoint=192.168.31.121:40456|interface=192.168.31.0/24|ttl=16";
but only sub1 can receive all messages, sub2 can not receive any messages.
I guess the "interface" paramter config may be not right.
I want to know how config channel udp multicast all subs can receive all messages?
thank you!

endpoint config udp multicast ip 224.0.1.1 is test pass。
pub: final String channel = "aeron:udp?endpoint=224.0.1.1:40456|interface=192.168.31.100|ttl=16";
sub1: final String channel = "aeron:udp?endpoint=224.0.1.1:40456|interface=192.168.31.120|ttl=16";
sub2: final String channel = "aeron:udp?endpoint=224.0.1.1:40456|interface=192.168.31.121|ttl=16";

Related

python3 sending string over udp without b'

In python3 when sending string over UDP, it has to be in form of bytes. It results with sending string "abc" like b'abc'. I want to send pure string like in python2.
Ia am using the code like this:
myInput = "abc"
mysocket.sendto(bytearray(myInput, 'utf-8'), (IP_address, port))
what the socket sends is
b'abc'
I know I can recieve it with decode:
msg, sender_address = mysocket.recvfrom(buf)
print(msg.decode())
However, I will have to recieve it with external device so I have to send it like:
abc
not
b'abc'

python socket to receive specific VLAN id packets

Is there a way to receive just VLAN id with 100 instead of receiving all packets? If so, what value the ntohs should have?
import socket
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(0x0003))
while True:
packet = s.recvfrom(65565)

Forwarding packets to windows

I wrote a code to send a packet from my Kali Linux machine to my Windows PC but the packet doesn't show in Wireshark. There are no errors in the code and it sends the packets but they are not received.
Any one can help ?
#!/usr/bin/python
from scapy.all import *
def synflood(src,tgt,message):
for dport in range(1024,65535):
IPlayer = IP(src=src, dst=tgt)
TCPlayer = TCP(sport=4444, dport=dport)
RAWlayer = Raw(load=message)
pkt = IPlayer/TCPlayer
send(pkt)
source = input("src: ")
target = input("targert : ")
message = input(" load : ")
while True:
synflood(source,target,message)
Update: So i fixed the problem! i tried replacing the for statement by "dport = 80" and for the target IP i chose another dest IP than my pc aand it showed up in wireshark, that's how i realised that i should configure an internal VM network instead of the bridged one , and it worked

Implementing reliability in UDP (python)

I have written the code for transferring an audio file from client to server using udp (python).
Now I am required to introduce reliability in the codes of UDP. The instructions are given as:
"You will be required to implement following to make UDP reliable:
(a) Sequence and acknowledge numbers
(b) Re-transmission (selective repeat)
(c) Window size of 5-10 UDP segments (stop n wait)
(d) Re ordering on receiver side "
THE SENDER THAT IS CLIENT CODE IS GIVEN BELOW
from socket import *
import time
# Assigning server IP and server port
serverName = "127.0.0.1"
serverPort = 5000
# Setting buffer length
buffer_length = 500
# Assigning the audio file a name
my_audio_file = r"C:\Users\mali.bee17seecs\PycharmProjects\TestProject\Aye_Rah-e-Haq_Ke_Shaheedo.mp3"
clientSocket = socket(AF_INET, SOCK_DGRAM)
# Opening the audio file
f = open(my_audio_file, "rb")
# Reading the buffer length in data
data = f.read(buffer_length)
# While loop for the transfer of file
while data:
if clientSocket.sendto(data, (serverName, serverPort)):
data = f.read(buffer_length)
time.sleep(0.02) # waiting for 0.02 seconds
clientSocket.close()
f.close()
print("File has been Transferred")
THE RECEIVER THAT IS SERVER CODE IS GIVEN BELOW
from socket import *
import select
# Assigning server IP and server port
serverName = "127.0.0.1"
serverPort = 5000
# Setting timeout
timeout = 3
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind((serverName, serverPort))
# While loop for the receiving of file
while True:
data, serverAddress = serverSocket.recvfrom(1024)
if data:
file = open(r"C:\Users\mali.bee17seecs\PycharmProjects\TestProject\Aye_Rah-e-Haq_Ke_Shaheedo.mp3",
"wb")
while True:
ready = select.select([serverSocket], [], [], timeout)
if ready[0]:
data, serverAddress = serverSocket.recvfrom(500)
file.write(data)
else:
file.close()
print("File has been Received")
break
Before answer each request, you should know that we build a reliable UDP by adding some specific infomation before the real content, which you can think as a application layer head. We use them to do some control or collect infomation like TCP does in traffic layer by the head part. It may look like below:
struct Head {
int seq;
int size;
}
(a) Sequence and acknowledge numbers
If you're familar with TCP, it is not hard. You can set seq and when the other side receive it, the controller will judge it and to check if we need to do b/d.
(b) Re-transmission (selective repeat) & (d) Reordering on receiver side
They are familiar to realise, using GBN/ARQ/SACK algorithm to do retransmission, using some simple algorithm like sorting to do reording.
(c) Window size of 5-10 UDP segments (stop n wait)
This part need to do some thing like traffic control that TCP does. I don't how complex you want to do, it's can be really complex or simple, it depends on you.

protobuf: string content is overlapped when 2 different instance of the same message in multithread

Recently I encountered a protobuf problem that the string was overlapped. The scenario is :
1/ defined a message like in proto file.
message fund_inout_rsp {
uint64 seq_no = 1;
uint32 err_id = 2;
string err_msg = 3
};
and then convert this message to C++ code using protoc --cpp_out。
so I got a class named fund_inout_rsp.
2/ Now there are two thread A and B.
In thread A,
fund_inout_rsp instance1;
instance1.set_err_msg(u8("123456789"))
instance1.SerializeToArray();
send out by TCP
In thread B,
fund_inout_rsp instance2;
instance2.set_err_msg(u8("abcd"));
instance2.SerializeToArray();
send out by TCP
3/ the TCP receiver got a message.
"abcd56789"
it seems that the instance1's err_msg is overlapped by instance2's err_msg.
The following is the auto generated code by protoc.
fund_inout_rsp::set_err_msg(const char* value) {
err_msg_.SetNoArena(
&google::protobuf::internal::GetEmptyStringAlreadyInited(),
std::string(value))
}
Can anyone give me a hint how to solve this problem?
Thanks in advance.

Resources