diff --git a/examples/interop_socket/main.c b/examples/interop_socket/main.c new file mode 100644 index 0000000000000000000000000000000000000000..b113dccccdc1a7f08d4cf2f37941ab72a59eadf0 --- /dev/null +++ b/examples/interop_socket/main.c @@ -0,0 +1,22 @@ +#include // socket addresses, constants +#include +#define BUFSIZE 512 +int main() { + // --- setup --- + struct sockaddr_in local, peer; + /* (address structure initializations omitted) */ + int fd = socket(AF_INET, SOCK_DGRAM, 0); + bind(fd, (const struct sockaddr *)&local, sizeof(local)); + connect(fd, (const struct sockaddr *)&peer, sizeof(peer)); + // --- communication --- + char buffer = malloc(BUFSIZE); + size_t msglen, i; + msglen = recv(fd, (const void *)buffer, BUFSIZE, 0); + for(i=0; i