This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <arpa/inet.h> | |
int main(int argc, char** argv) | |
{ | |
int sd; | |
struct sockaddr_in addr; | |
struct sockaddr_in c_addr; | |
if((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { | |
perror("socket"); | |
return EXIT_SUCCESS; | |
} | |
c_addr.sin_family = AF_INET; | |
c_addr.sin_port = htons(33400); | |
c_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); | |
if (bind(sd, (struct sockaddr*)&c_addr, sizeof(c_addr))) { | |
perror("client bind"); | |
return EXIT_FAILURE; | |
} | |
addr.sin_family = AF_INET; | |
addr.sin_port = htons(22222); | |
addr.sin_addr.s_addr = inet_addr("127.0.0.1"); | |
connect(sd, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)); | |
if(send(sd, "I am send process", 17, 0) < 0) { | |
perror("send"); | |
return EXIT_FAILURE; | |
} | |
close(sd); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment