简体   繁体   中英

Sockets UDP TCP C

I have a question: Is it possible to execute sendto to send information from one process which is initialized on UDP to another process initialized on TCP (this is all in the same .c )?.

I have one process which receives information on UDP and this one has to send this information locally to the TCP one and I don't know how to connect (I know you cannot connect with UDP, I mean just send the datagram) them. Can anyone help me?

Thank you.

You can send udp datagrams from a UDP socket to a UDP socket. You can send byte streams from a TCP socket to a TCP socket.

If you want to use a socket for inter-process communication, then both processes need use the same type of socket.

The process that is receiving UDP packets has to open a separate TCP socket to send to the other process.

So at startup this process should first open up a UDP socket to receive datagrams. Then it gets a TCP socket and uses that to connect to the other process using the connect function. Then, whenever data comes in on the UDP socket, you take that data and send it out using send over the TCP socket for the other server to read.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM