목록TCP IP 소켓 프로그래밍 (13)
printf("ho_tari\n");
#include #include #include #include void* thread_main1(void *arg); void* thread_main2(void *arg); void* thread_main3(void *arg); static sem_t sem_one; static sem_t sem_two; static sem_t sem_three; int main(int argc, char *argv[]) { pthread_t t1_id, t2_id, t3_id; int thread_param=5; sem_init(&sem_one, 0, 0); sem_init(&sem_two, 0, 0); sem_init(&sem_three, 0, 1); pthread_create(&t1_id, NULL, thread..
#include #include #include void * read(void * arg); void * accu(void * arg); static sem_t sem_one; static sem_t sem_two; static int num; int main(int argc, char *argv[]) { pthread_t id_t1, id_t2; sem_init(&sem_one, 0, 0); sem_init(&sem_two, 0, 1); pthread_create(&id_t1, NULL, read, NULL); pthread_create(&id_t2, NULL, accu, NULL); pthread_join(id_t1, NULL); pthread_join(id_t2, NULL); sem_destroy(..
#include #include #define NUM_THREAD100 void * thread_inc(void * arg); void * thread_des(void * arg); long long num=0; pthread_mutex_t mutex; int main(int argc, char *argv[]) { pthread_t thread_id[NUM_THREAD]; int i; pthread_mutex_init(&mutex, NULL); printf("sizeof long long: %d \n", sizeof(long long)); for(i=0; i
#include #include #include #include void error_handling(char *message); int main(int argc, char *argv[]) { int sock; int snd_buf, rcv_buf, state; socklen_t len; sock=socket(PF_INET, SOCK_STREAM, 0); len=sizeof(snd_buf); state=getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (void*)&snd_buf, &len); if(state) error_handling("getsockopt() error"); len=sizeof(rcv_buf); state=getsockopt(sock, SOL_SOCKET, SO_R..
#include #include #include #include #include void error_handling(char *message); int main(int argc, char *argv[]) { int i; struct hostent *host; if(argc!=2) { printf("Usage : %s \n", argv[0]); exit(1); } host=gethostbyname(argv[1]); if(!host) error_handling("gethost... error"); printf("Official name: %s \n", host->h_name); for(i=0; host->h_aliases[i]; i++) printf("Aliases %d: %s \n", i+1, host->..
#include #include #include #include #include #include #define BUF_SIZE 1024 void error_handling(char *message); int main(int argc, char *argv[]) { int sock; char message[BUF_SIZE]; int str_len, recv_len, recv_cnt; struct sockaddr_in serv_adr; if (argc != 3) { printf("Usage : %s \n", argv[0]); exit(1); } // 소켓 생성 sock = socket(PF_INET, SOCK_STREAM, 0); if (sock == -1) error_handling("socket() err..
#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_STREAM, 0); if..
#include #include int main(int argc, char *argv[]) { char *addr1="127.212.124.78";// 0x4E7CD47F(78.124.212.127) char *addr2="127.212.124.255"; unsigned long conv_addr=inet_addr(addr1); if(conv_addr==INADDR_NONE) printf("Error occured! \n"); else printf("Network ordered integer addr: %#lx \n", conv_addr); conv_addr=inet_addr(addr2); if(conv_addr==INADDR_NONE) printf("Error occureded \n"); else pr..