Hi friends,
From a (windows os) souce IP : 192.168.10.10 a unicasted udp message is coming to
(rhel Linux OS) destination IP : 192.168.10.40, dest port : 2000
Line : addr, data = recvfrom(recv_sock)
I have written a Julia program below to broadcast this message (coming to 192.168.10.40, dest port : 2000)
Julia program is running on rhel Linux OS.
My intention is to make two other programs (running on rhel linux os) to receive the udp packets
unicasted to IP : 192.168.10.40, dest port : 2000.
send(send_sock, IPv4(DEST_IP_2), DEST_PORT_2, data,reuseaddr = true)
Giving error : Forward failed: MethodError(Core.kwcall, ((reuseaddr = true,), Sockets.send, UDPSocket(init), ip"192.168.10.255", 11000,
on line : println(“✗ Forward failed: $forward_error”)
The program is given below
#!/usr/bin/env julia
using Sockets
using Dates
# Configuration
DEST_IP = "192.168.10.40"
DEST_PORT = 2000
SOURCE_IP = "192.168.10.10"
SOURCE_PORT = 5000
#Broadcast Forward configuration
DEST_IP_2 = "192.168.10.255"
DEST_PORT_2 = 11000
println("="^60)
println("UDP Packet Receiver and Forwarder")
println("="^60)
println("Listening on: $DEST_IP:$DEST_PORT")
println("Expected source: $SOURCE_IP:$SOURCE_PORT")
println("Forwarding to: $DEST_IP_2:$DEST_PORT_2")
println("="^60)
println()
# Create UDP sockets
recv_sock = UDPSocket()
send_sock = UDPSocket()
try
# Bind receiver socket to the destination IP and port
bind(recv_sock, ip"192.168.10.40", DEST_PORT,reuseaddr = true)
println("✓ Receiver socket bound successfully")
#ccall(:jl_tcp_setsockopt, Cint, (Ptr{Cvoid}, Cint, Cint, Cint),send_sock.handle, 1, 6, 1) # SOL_SOCKET=1, SO_BROADCAST=6
# Enable broadcast on sender socket (needed for 192.168.10.255)
# This is automatic in Julia's UDPSocket
println("✓ Sender socket created")
println("Waiting for packets... (Press Ctrl+C to stop)")
println()
packet_count = 0
while true
# Receive data (this will block until data arrives)
# recvfrom returns (address, data) tuple
addr, data = recvfrom(recv_sock)
packet_count += 1
# Forward the packet to DEST_IP_2
try
send(send_sock, IPv4(DEST_IP_2), DEST_PORT_2, data,reuseaddr = true)
println("✓ Forwarded to: $DEST_IP_2:$DEST_PORT_2")
catch forward_error
println("✗ Forward failed: $forward_error")
end
println()
end
catch e
if isa(e, InterruptException)
println("\n\n✓ Receiver stopped by user")
else
println("\n✗ Error occurred:")
println(e)
println()
# Print stack trace for debugging
for (exc, bt) in Base.catch_stack()
showerror(stdout, exc, bt)
println()
end
end
finally
close(recv_sock)
close(send_sock)
println("Sockets closed")
end