This file is part of eRCaGuy_hello_world: https://github.com/ElectricRCAircraftGuy/eRCaGuy_hello_world
Unix socket
interface: sockets, Ethernet, TCP vs UDP packets, client/server examples, etc.
I've done a lot of Googling and looked at a lot of resources now, and none of it seems to be great material so far on the topic of learning sockets and Ethernet packets and seeing good UDP and TCP server/client C examples, except perhaps GeeksForGeeks. We shall see. Study these:
-
GeeksforGeeks
- https://www.geeksforgeeks.org/socket-programming-cc/
- *****TCP Server-Client implementation in C
- *****UDP Server-Client implementation in C
- https://www.geeksforgeeks.org/differences-between-tcp-and-udp/?ref=lbp
- https://www.geeksforgeeks.org/user-datagram-protocol-udp/
- https://www.geeksforgeeks.org/why-does-dns-use-udp-and-not-tcp/
-
Google search for "c socket client server demo"
-
TCP server example: see the bottom of this man page here: https://linux.die.net/man/2/bind. They cover all of these steps:
- Create the socket, bind it, listen, accept an incoming connection.
-
My work:
- socket__geeksforgeeks_udp_client_GS_edit_GREAT.c
- socket__geeksforgeeks_udp_server_GS_edit_GREAT.c
- Stack Overflow: Is TCP bidirectional or full-duplex?
- Stack Overflow: Why should I use, or not use, MSG_CONFIRM?
- Stack Overflow: What is SOCK_DGRAM and SOCK_STREAM? - has my macros like this, too, from my example code here: socket__geeksforgeeks_udp_server_GS_edit_GREAT.c:
// See: https://linux.die.net/man/7/ip // AF = "Address Family" // INET = "Internet" // AF_INET = IPv4 internet protocols // AF_INET6 = IPv6 internet protocols; see: https://linux.die.net/man/2/socket // DGRAM = "Datagram" (UDP) // // IPv4 #define SOCKET_TYPE_TCP_IPV4 AF_INET, SOCK_STREAM, 0 #define SOCKET_TYPE_UDP_IPV4 AF_INET, SOCK_DGRAM, 0 #define SOCKET_TYPE_RAW_IPV4(protocol) AF_INET, SOCK_RAW, (protocol) // IPv6 #define SOCKET_TYPE_TCP_IPV6 AF_INET6, SOCK_STREAM, 0 #define SOCKET_TYPE_UDP_IPV6 AF_INET6, SOCK_DGRAM, 0 #define SOCKET_TYPE_RAW_IPV6(protocol) AF_INET6, SOCK_RAW, (protocol)
- Excellent example of this!:
- UDP server: socket__geeksforgeeks_udp_server_GS_edit_GREAT.c
- UDP client: socket__geeksforgeeks_udp_client_GS_edit_GREAT.c