nginx proxy unidirectional udp connection to HTTPS connection - sockets

I need to forward an unidirectional stream of udp packets from one side to an HTTPS connection on the other end.
I can potentially solve it using python, but this server should be able to forward large amount of traffic so I would like to rely on Nginx for this task.
can Nginx do such a thing?
What I tried
I tried:
stream {
server {
listen 9990 udp;
proxy_pass localhost:9995;
}
}
which forward correctly UDP packets.
I tested it running 2 servers
nc -u -l 9995 # listen on udp port 9995
nc -u localhost 9990 # send packets to nginx listening on udp port 9990
this test worked when both connections are udp. my goal to listen on TCP on port 9995 instead of udp, currently I couldn't do it with nginx.
Why?
additional context, not part of the question
I have a wire that can transfer packets only in one direction. so TCP connection can't be established. the other end requires https connection, so I can go around this by another server in the middle that will accept udp socket on one end and http/tcp socket on the other end, that will forward any udp packet coming from one end as an HTTP msg over TCP with the other end

Related

SOCAT - Forwarding TCP packets to UDP

I have an application that sends simple data over TCP (simple, no auth) and another application that must receive it. The only allowed connection between the two is UDP.
On the receiving side, I have SOCAT listening for incoming UDP packets and forwarding them via a TCP connection to the computer that hosts the software.
socat UDP4-LISTEN:5000, fork TCP-CONNECT:192.168.1.5:5001
On the sending side, I can send test data via
socat UDP4-connect 192.168.1.1:5000
There is a firewall in the way and I have no control over it which is why UDP is my only option. The firewall allows UDP out from the sender and UDP in to the receiver.
What I don't know is how to take a TCP connection on the sender and forward its output via UDP. And I don't know if this is the best way or if it will work at all.
Thank you

listen to any port in tcp server

I Work with a Hardware and I can ping with it.I write a TCP server App that listen to special port and and special IP (My hardware Ip). the hardware send data in ip and port that I don't know, so how can I get data from my hardware with TCP protocol?

Can a server which acts both as RMI and UDP server listen to requests on the same port number?

I'm working on a program in which a UDP server keeps listening to incoming requests.
If a particluar kind of request is received, it tries to create a RMI server using the same port on which the UDP server was listening.
So, is this possible?
or I need to have different ports?
Yes it's possible. TCP and UDP port numbers are in different namespaces.

multiple connections on one port

I run multiple bonjour client using pidgin, A, B, and C.
when B and C talk to A , I find A uses the same port (with wireshark I can see the packets) for MDNS and communication,
but B and C, each has two different ports one for MDNS ,one for socket connection.
how does A work, why it can work with only one port? how can one port provides multiple connections?
Attention: if it is multithread ,then when it accepts a connection it will create a new socket with another free port, but I saw the packets from wireshark, client A did just use the same port for communication and MDNS.
A TCP connection is actually identified by the tuple: (source_address, source_port, destination_address, destination_port). So as long as one of these is different there is no problem.
In practice, what you say happens when a program listens for connections in a given port: any new connection is created with the same server port (but different client port or address).
For exmample, in my Linux machine, where I have a web server listening at port 80:
$ telnet localhost 80 &
$ telnet localhost 80 &
$ lsof -n -i TCP
...
TCP 127.0.0.1:45601->127.0.0.1:80
TCP 127.0.0.1:45602->127.0.0.1:80

Can TCP and UDP sockets use the same port?

First of all, is there any problem with using both UDP and TCP on the same server?
Secondly, can I use the same port number?
Yes, you can use the same port number for both TCP and UDP. Many protocols already do this, for example DNS works on udp/53 and tcp/53.
Technically the port pools for each protocol are completely independent, but for higher level protocols that can use either TCP or UDP it's convention that they default to the same port number.
When writing your server, bear in mind that the sequence of events for a TCP socket is much harder than for a UDP socket, since as well as the normal socket and bind calls you also have to listen and accept.
Furthermore that accept call will return a new socket and it's that socket that you'll then have to also poll for receive events. Your server should be prepared to continue accepting connections on the original socket whilst simultaneously servicing multiple clients each of which will be triggering receive events on their own sockets.
Firstly,there is no problem using both tcp and udp on the server.
Secondly,we can have both UDP and TCP requests on same port ,because each request is identified by a quintuple contained by source IP ,Destination IP, Source Port, Destination Port, PROTOCOL(as protocol can be TCP or UDP).