본문 바로가기

임베디드/C언어 소켓 통신14

리눅스 개발 환경 - vmware 우분투 설치 2020. 12. 24.
TEST1008 server#include #include #include #include #include #include #include #include #define BUF_SIZE100 #define SERVER_IPINADDR_ANY //문제1. IP #define SERVER_PORT"9987" //문제1. 포트번호 struct user { char id[10]; char sock_num; }; struct user aa[10]; void error_handling(char *buf); int main() { int sock_check; int serv_sock, clnt_sock; struct sockaddr_in serv_adr, clnt_adr; struct timeval timeout; fd_set re.. 2020. 10. 8.
makefile # #타겟 : 의존성 # 명령어 CC = gcc CFLAGS = -W -Wall TARGET = echo_selectserv OBJECT = echo_selectserv.o SRC = echo_selectserv.c $(TARGET) : $(OBJECT) $(CC) $(CFLAGS) -o $(TARGET) $(OBJECT) $(OBJECT): $(SRC) $(CC) $(CFLAGS) -c -o $(OBJECT) $(SRC) clean: rm *.o $(TARGET) 2020. 10. 8.
구조체 사용 server #include #include #include #include #include #include #include #include #define BUF_SIZE 100 #define SERVER_IP INADDR_ANY #define SERVER_PORT "7777" //구조체 struct user { // < 여기 적어주는 _STUDENT 는 코드상 큰 의미는 없다. 하지만 적어주는 이유는 구조체가 중복되어 코딩되는 것을 방지하기 위해 관례적으로 적어준다. char id[20]; char sock_num; }; struct user us[20]; void error_handling(char *buf); int main(/*int argc, char *argv[]*/) { int sock_ch.. 2020. 10. 8.
enterID - 개행문자 없애기 echo_selectserv.c #include #include #include #include #include #include #include #include #define BUF_SIZE100 #define SERVER_IPINADDR_ANY #define SERVER_PORT"9987" void error_handling(char *buf); int main(/*int argc, char *argv[]*/) { int serv_sock, clnt_sock; struct sockaddr_in serv_adr, clnt_adr; struct timeval timeout; fd_set reads, cpy_reads; socklen_t adr_sz; int fd_max, str_len, fd_num, i;.. 2020. 10. 6.
echo_client.c echo_selectserv.c echo_selectserv.c #include #include #include #include #include #include #include #include #define BUF_SIZE100 #define SERVER_IPINADDR_ANY #define SERVER_PORT"9987" void error_handling(char *buf); int main(/*int argc, char *argv[]*/) { int serv_sock, clnt_sock; struct sockaddr_in serv_adr, clnt_adr; struct timeval timeout; fd_set reads, cpy_reads; socklen_t adr_sz; int fd_max, str_len, fd_num, i;.. 2020. 9. 29.
echo_selectserv echo_client echo_selectserv.c #include #include #include #include #include #include #include #include #define BUF_SIZE 100 void error_handling(char *buf); int main(int argc, char *argv[]) { int serv_sock, clnt_sock; struct sockaddr_in serv_adr, clnt_adr; struct timeval timeout; fd_set reads, cpy_reads; socklen_t adr_sz; int fd_max, str_len, fd_num, i; char buf[BUF_SIZE]; if(argc!=2) { printf("Usage : %s \n".. 2020. 9. 29.
chpt12. echo_select #include #include #include #include #include #include #include #include #define BUF_SIZE 100 void error_handling(char *buf); int main(int argc, char *argv[]) { int serv_sock, clnt_sock; struct sockaddr_in serv_adr, clnt_adr; struct timeval timeout; fd_set reads, cpy_reads; socklen_t adr_sz; int fd_max, str_len, fd_num, i; char buf[BUF_SIZE]; if(argc!=2) { printf("Usage : %s \n", argv[0]); exit(1.. 2020. 9. 25.
echo_server.c echo_client.c echo_server.c #include #include #include #include #include #include #define BUF_SIZE 1024 void error_handling(char *message); int main(int argc, char *argv[]) { int serv_sock, clnt_sock; char message[BUF_SIZE]; int str_len, i; struct sockaddr_in serv_adr; struct sockaddr_in clnt_adr; socklen_t clnt_adr_sz; if(argc!=2) { printf("Usage : %s \n", argv[0]); exit(1); } serv_sock=socket(PF_INET, SOCK_.. 2020. 9. 24.
hello server (client ->server) hello_client.c #include #include #include #include #include #include #define SERVER_IP"127.0.0.1" #define SERVER_PORT "9988" void error_handling(char *message); int main(int argc, char* argv[]) { int serv_sock; int clnt_sock; int sock; struct sockaddr_in serv_addr; //char message[30] = {0,}; //초기화 하는것이 더 좋다 int str_len = 0; //초기화 하는것이 더 좋다 /* if(argc!=3){ printf("Usage : %s \n", argv[0]); exit(1.. 2020. 9. 24.
hello server (client ->server) hello_client.c #include #include #include #include #include #include #define SERVER_IP"127.0.0.1" #define SERVER_PORT "9988" void error_handling(char *message); int main(int argc, char* argv[]) { int serv_sock; int clnt_sock; int sock; struct sockaddr_in serv_addr; //char message[30] = {0,}; //초기화 하는것이 더 좋다 int str_len = 0; //초기화 하는것이 더 좋다 /* if(argc!=3){ printf("Usage : %s \n", argv[0]); exit(1.. 2020. 9. 23.
Sever socket created Sever socket binding Sever socket listening hello_server.c #include #include #include #include #include #include #define SERVER_IP INADDR_ANY #define SERVER_PORT "9988" void error_handling(char *message); int main(int argc, char *argv[]) { int serv_sock; int clnt_sock; struct sockaddr_in serv_addr; struct sockaddr_in clnt_addr; socklen_t clnt_addr_size; char message[]="Hello World!"; /* if(argc!=2){ printf("Usage : %s \n", argv[0]); exit(.. 2020. 9. 23.
c언어 소켓통신 hello_client.c #include #include #include #include #include #include void error_handling(char *message); int main(int argc, char* argv[]) { int sock; struct sockaddr_in serv_addr; char message[30]; int str_len; if(argc!=3){ printf("Usage : %s \n", argv[0]); exit(1); } sock=socket(PF_INET, SOCK_STREAM, 0); if(sock == -1) error_handling("socket() error"); memset(&serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_f.. 2020. 9. 23.
C언어 소켓통신 hello_server.c https://m.blog.naver.com/PostView.nhn?blogId=wndrlf2003&logNo=220001255564&proxyReferer=https:%2F%2Fwww.google.com%2F 네트워크기초 11주차(2) (TCP/IP 1:1 에코서버 C로 작성, 클라이언트 대기 방식) > 네트워크기초 11주차(2) (TCP/IP 1:1 에코서버 C로 작성, 클라이언트 대기 방식) └ 접기 blog.naver.com #include // ANSI C #include // ANSI C #include // ANSI C #include // unix 표준 #include //버클리 소켓 #include //소켓 기본 void error_handling(char* message); int ma.. 2020. 9. 23.