6 장과제샘플코드 - 다자간채팅 (udp 버전 1) 목포해양대해양컴퓨터공학과

Size: px
Start display at page:

Download "6 장과제샘플코드 - 다자간채팅 (udp 버전 1) 목포해양대해양컴퓨터공학과"

Transcription

1 6 장과제샘플코드 - 다자간채팅 (udp 버전 1)

2 과제 서버에서먼저 bind 하고그포트를다른사람에게알려줄것 클라이언트들은알려준포트로접속 서버는클라이언트로부터받은메시지를다른클라이언트들에게전달 2

3 Makefile 1 SRC_DIR =../../common 2 COM_OBJS = $(SRC_DIR)/addressUtility.o $(SRC_DIR)/dieWithMessage.o umcprotocol.o 3 SRV_OBJS = umcserver.o umcserverprocess.o 4 CLI_OBJS = umcclient.o umcclientprocess.o 5 6 CFLAGS = -g -std=gnu99 7 CC = gcc 8 9 all: 10 make umcserver 11 make umcclient umcserver : $(COM_OBJS) $(SRV_OBJS) 14 gcc -o umcserver $(CFLAGS) $(COM_OBJS) $(SRV_OBJS) umcclient : $(COM_OBJS) $(CLI_OBJS) 17 gcc -o umcclient $(CFLAGS) $(COM_OBJS) $(CLI_OBJS) install : 20 mv umcserver umcclient ~/bin clean : 23 rm *.o umcserver umcclient 3

4 umcprotocol.h (1) 1 #ifndef UMC_PROTOCOL_H_ 2 #define UMC_PROTOCOL_H_ 3 4 #include <stdint.h> 5 #include <unistd.h> 6 7 enum { 8 MAX_WIRE_SIZE = 512, 9 MAX_MSG_SIZE = 500, 10 MAX_SILENT_TIME = }; typedef enum { 14 JOIN_REQ = 1, 15 JOIN_ACK = 2, 16 DATA_REQ = 3, 17 DATA_ACK = 4, 18 MESSAGE = 5, 19 CHK_REQ = 6, 20 CHK_ACK = 7, 21 LEAVE_REQ = 8, 22 LEAVE_ACK = 9, 23 ERROR = } f_code_t; 25 4

5 umcprotocol.h (2) 26 typedef struct { 27 uint32_t msg_size; 28 uint8_t msg_data[max_msg_size]; 29 } msg_t; typedef struct { 32 f_code_t fcode; 33 msg_t message; 34 } mcht_t; #define MAGIC_NUMBER 0x typedef struct { 40 uint32_t magic_no; 41 uint32_t fcode; 42 msg_t message; 43 } mcht_pdu_t; int mk_pdu(const mcht_t *mcht_ptr, mcht_pdu_t *pdu_ptr); 47 int parse_pdu(const mcht_pdu_t *pdu_ptr, mcht_t *mcht_ptr); 48 #endif 5

6 umcprotocol.c (1) 1 #include "umcprotocol.h" 2 3 #include <stdio.h> 4 #include <string.h> 5 #include <arpa/inet.h> 6 7 /******************************************************************************/ 8 int mk_pdu(const mcht_t *mcht_ptr, mcht_pdu_t *pdu_ptr) 9 { 10 pdu_ptr->magic_no = htonl(magic_number); pdu_ptr->fcode = htonl(mcht_ptr->fcode); 13 if ((mcht_ptr->fcode == JOIN_REQ) 14 (mcht_ptr->fcode == DATA_REQ) 15 (mcht_ptr->fcode == MESSAGE)) { if (mcht_ptr->message.msg_size >= MAX_MSG_SIZE) { 18 fprintf(stderr, "Out of message length limit!\n"); 19 return 0; 20 } 21 pdu_ptr->message.msg_size = htonl(mcht_ptr->message.msg_size); 22 strncpy(pdu_ptr->message.msg_data, 23 mcht_ptr->message.msg_data, 24 mcht_ptr->message.msg_size); 25 } 26 return 1; 27 } 6

7 umcprotocol.c (2) 28 /******************************************************************************/ 29 int parse_pdu(const mcht_pdu_t *pdu_ptr, mcht_t *mcht_ptr) 30 { 31 if (ntohl(pdu_ptr->magic_no)!= MAGIC_NUMBER) { 32 fprintf(stderr, "invalid MAGIC_NUMBER!\n"); 33 return 0; 34 } mcht_ptr->fcode = (f_code_t)ntohl(pdu_ptr->fcode); 37 if ((mcht_ptr->fcode == JOIN_REQ) 38 (mcht_ptr->fcode == DATA_REQ) 39 (mcht_ptr->fcode == MESSAGE)) { 40 mcht_ptr->message.msg_size = ntohl(pdu_ptr->message.msg_size); if (mcht_ptr->message.msg_size >= MAX_MSG_SIZE) { 43 fprintf(stderr, "Out of message length limit!\n"); 44 return 0; 45 } 46 strncpy(mcht_ptr->message.msg_data, 47 pdu_ptr->message.msg_data, 48 mcht_ptr->message.msg_size); 49 } 50 return 1; 51 } 7

8 umcclientprocess.h 1 #ifndef _UMC_CLIENT_PROCESS_H 2 #define _UMC_CLIENT_PROCESS_H 3 4 #define QUIT_STR "QUIT" 5 6 int read_and_sendto(int ifd, int sock, struct sockaddr *toaddr); 7 int recvfrom_and_process(int sock, struct sockaddr *fromaddr, int ofd); 8 int join_request(int sock, struct sockaddr *toaddr, char *nickname); 9 10 #endif 8

9 umcclientprocess.c (1) 1 #include <stdlib.h> 2 #include <string.h> 3 #include <sys/types.h> 4 #include <sys/socket.h> 5 #include <netdb.h> 6 #include "../../common/practical.h" 7 8 #include "umcprotocol.h" 9 #include "umcclientprocess.h" 10 9

10 umcclientprocess.c (2) 11 /******************************************************************************/ 12 int join_request(int sock, struct sockaddr *toaddr, char *nickname) 13 { 14 mcht_t mcht_str = {0}; mcht_str.fcode = JOIN_REQ; 17 strncpy(mcht_str.message.msg_data, nickname, MAX_MSG_SIZE); 18 mcht_str.message.msg_size = strlen(mcht_str.message.msg_data); mcht_pdu_t send_pdu; if (!mk_pdu(&mcht_str, &send_pdu)) { 23 fprintf(stderr, "mk_pdu ERROR!\n"); 24 return 0; 25 } int pdu_size = sizeof(send_pdu); 28 ssize_t numbytessent = sendto(sock, &send_pdu, pdu_size, 0, 29 toaddr, sizeof(*toaddr)); if (numbytessent!= pdu_size) { 32 fprintf(stderr, "sendto ERROR!\n"); 33 return 0; 34 } return 1; 37 } 38 10

11 umcclientprocess.c (3) 39 /******************************************************************************/ 40 int read_and_sendto(int ifd, int sock, struct sockaddr *toaddr) 41 { 42 mcht_t mcht_str = {0}; if (read(ifd, mcht_str.message.msg_data, MAX_MSG_SIZE) <= 0) { 45 fprintf(stderr, "Read ERROR!\n"); 46 return 0; 47 } if (strncmp(mcht_str.message.msg_data, QUIT_STR, strlen(quit_str)) == 0) { 50 mcht_str.fcode = LEAVE_REQ; 51 } 52 else { 53 mcht_str.fcode = DATA_REQ; 54 mcht_str.message.msg_size = strlen(mcht_str.message.msg_data); 55 } 56 11

12 umcclientprocess.c (4) 57 mcht_pdu_t send_pdu; if (!mk_pdu(&mcht_str, &send_pdu)) { 60 fprintf(stderr, "mk_pdu ERROR!\n"); 61 return 0; 62 } int pdu_size = sizeof(send_pdu); 65 ssize_t numbytessent = sendto(sock, &send_pdu, pdu_size, 0, 66 toaddr, sizeof(*toaddr)); if (numbytessent!= pdu_size) { 69 fprintf(stderr, "sendto ERROR!\n"); 70 return 0; 71 } return 1; 74 } 75 12

13 umcclientprocess.c (5) 76 /******************************************************************************/ 77 int recvfrom_and_process(int sock, struct sockaddr *fromaddr, int ofd) 78 { 79 mcht_pdu_t mcht_pdu = {0}; // for receiving int addrlen; 82 ssize_t numbytesrcvd = recvfrom(sock, &mcht_pdu, MAX_WIRE_SIZE, 0, 83 fromaddr, &addrlen); 84 if (numbytesrcvd < 0) 85 return 0; mcht_t mcht_str = {0}; 88 mcht_t new_mcht_str = {0}; if (!parse_pdu(&mcht_pdu, &mcht_str)) { 91 fprintf(stderr, "parse_pdu ERROR!\n"); 92 return 0; 93 } char msgbuf[max_msg_size] = {0}; 13

14 umcclientprocess.c (6) 97 switch(mcht_str.fcode) { 98 case JOIN_ACK: 99 sprintf(msgbuf, " 연결되었습니다.\n"); if (write(ofd, msgbuf, MAX_MSG_SIZE) <= 0) { 102 fprintf(stderr, "Write ERROR!\n"); 103 return 0; 104 } 105 break; case LEAVE_ACK: 108 sprintf(msgbuf, " 탈퇴하였습니다.\n"); if (write(ofd, msgbuf, MAX_MSG_SIZE) <= 0) { 111 fprintf(stderr, "Write ERROR!\n"); 112 return 0; 113 } 114 DieWithSystemMessage(" 정상종료합니다.\n"); 115 break; 116 case DATA_ACK: // do nothing 117 break; 14

15 umcclientprocess.c (7) 124 case CHK_REQ: 125 new_mcht_str.fcode = CHK_ACK; mcht_pdu_t send_pdu; 128 if (!mk_pdu(&new_mcht_str, &send_pdu)) { 129 fprintf(stderr, "mk_pdu ERROR!\n"); 130 return 0; 131 } 132 int pdu_size = sizeof(send_pdu); 133 ssize_t numbytessent = sendto(sock, &send_pdu, pdu_size, 0, 134 fromaddr, sizeof(*fromaddr)); if (numbytessent!= pdu_size) { 137 fprintf(stderr, "sendto ERROR!\n"); 138 return 0; 139 } 140 break; 141 default: // others : JOIN_REQ, DATA_REQ, CHK_ACK, LEAVE_REQ 142 fprintf(stderr, "invalid fcode!\n"); 143 return 0; 144 } return 1; 147 } 15

16 umcclient.c (1) 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <unistd.h> 5 #include <sys/socket.h> 6 #include <netdb.h> 7 #include "../../common/practical.h" 8 #include "umcprotocol.h" 9 #include "umcclientprocess.h" /******************************************************************************/ 12 int main(int argc, char *argv[]) { if (argc!= 4 ) // 명령어행인자의개수가알맞은지확인 15 DieWithUserMessage("Parameter(s)", 16 "<Server Address/Name> <Server Port/Service> <nickname>"); char *server = argv[1]; // 첫번쨰인자 : 서버의주소 / 이름 19 char *servport = argv[2]; // 두번째인자 : 서버포트 / 서비스이름 20 char *nickname = argv[3]; // 세번째인자 : 별명 21 16

17 umcclient.c (2) 22 // 어떤형태의주소를원하는지시스템에알림 23 struct addrinfo addrcriteria; // 원하는주소기준설정 24 memset(&addrcriteria, 0, sizeof(addrcriteria)); // 구조체를 0으로초기화 25 addrcriteria.ai_family = AF_UNSPEC; // IPV4,IPV6 모두반환 26 addrcriteria.ai_socktype = SOCK_DGRAM; // 데이터그램소켓만반환 27 addrcriteria.ai_protocol = IPPROTO_UDP; // UDP만반환 // 주소들획득 struct addrinfo *addr; 32 struct addrinfo *servaddr; // 서버주소의리스트 int rtnval = getaddrinfo(server, servport, &addrcriteria, &servaddr); 35 if (rtnval!= 0) 36 DieWithUserMessage("getaddrinfo() failed", gai_strerror(rtnval)); int sock = -1; 39 for (addr = servaddr; addr!= NULL; addr = addr->ai_next) { 40 // 데이터그램 UDP소켓생성 41 sock = socket(addr->ai_family, addr->ai_socktype, 42 addr->ai_protocol); // 클라이언트소켓식별자 43 if (sock > 0) 44 break; 45 } join_request(sock, addr->ai_addr, nickname); 17

18 umcclient.c (3) 49 fd_set master_set, read_set; FD_ZERO(&master_set); 52 FD_SET(0, &master_set); 53 FD_SET(sock, &master_set); while(read_set = master_set, select(sock+1, &read_set, NULL, NULL, NULL) > 0) { 56 if (FD_ISSET(0, &read_set)) { 57 if (!read_and_sendto(0, sock, addr->ai_addr)) 58 DieWithSystemMessage("sendto() failed"); 59 } if (FD_ISSET(sock, &read_set)) { 62 struct sockaddr_storage fromaddr; if (!recvfrom_and_process(sock, (struct sockaddr *) &fromaddr, 1)) { 65 DieWithSystemMessage("recvfrom() failed"); 66 } 67 } 68 } freeaddrinfo(servaddr); 71 close(sock); exit(0); 74 } 18

19 umcserverprocess.h 1 #ifndef _UMC_SERVER_PROCESS_H 2 #define _UMC_SERVER_PROCESS_H 3 4 #include <time.h> 5 6 #define MAX_IDLE_TIME 60 7 #define MAX_NAME_SIZE typedef struct _clnt_record { 10 uint8_t nickname[max_name_size]; 11 struct sockaddr clnt_addr; 12 time_t last_atime; 13 struct _clnt_record *next; 14 } clnt_record_t; int recvfrom_and_serve(int sockfd, struct sockaddr *fromaddr, socklen_t addrlen, 17 clnt_record_t **hd_ptr); 18 int join_process(mcht_t *mcht_str, struct sockaddr *fromaddr, clnt_record_t **hd_ptr) ; 19 int leave_process(struct sockaddr *fromaddr, clnt_record_t **hd_ptr); 20 int data_process(int sockfd, mcht_t *mcht_str, struct sockaddr *fromaddr, i 21 clnt_record_t *hd_ptr); 22 int chk_alive(int sock, clnt_record_t *hd_ptr); 23 int update_client_status(struct sockaddr *fromaddr, clnt_record_t *hd_ptr); 24 int prnt_clnt_list(clnt_record_t *hd_ptr); #endif 19

20 umcserverprocess.c (1) 1 #include <stdlib.h> 2 #include <string.h> 3 #include <sys/types.h> 4 #include <sys/socket.h> 5 #include <netdb.h> 6 #include <time.h> 7 8 #include "../../common/practical.h" 9 #include "umcprotocol.h" 10 #include "umcserverprocess.h" /******************************************************************************/ 13 int recvfrom_and_serve(int sockfd, struct sockaddr *fromaddr, socklen_t addrlen, 14 clnt_record_t **hd_ptr) 15 { 16 socklen_t fromaddrlen = addrlen; 17 mcht_pdu_t recv_pdu; ssize_t numbytesrcvd = recvfrom(sockfd, &recv_pdu, sizeof(recv_pdu), 0, 20 fromaddr, &fromaddrlen); 21 if (numbytesrcvd < 0) { 22 fprintf(stderr, "recv_from ERROR!\n"); 23 return 0; 24 } 25 20

21 umcserverprocess.c (2) 26 mcht_t mcht_str = {0}; 27 mcht_t resp_mcht_str = {0}; 28 mcht_pdu_t send_pdu = {0}; if (!parse_pdu(&recv_pdu, &mcht_str)) { 31 fprintf(stderr, "parse_pdu ERROR!\n"); 32 return 0; 33 } // fprintf(stderr, "arrived: %d\n", mcht_str.fcode); 36 prnt_clnt_list(*hd_ptr); if (mcht_str.fcode == CHK_ACK) { 39 update_client_status(fromaddr, *hd_ptr); 40 return 1; 41 } 42 else { if (mcht_str.fcode == JOIN_REQ) { 45 if (join_process(&mcht_str, fromaddr, hd_ptr)) { 46 resp_mcht_str.fcode = JOIN_ACK; 47 } 48 else { 49 resp_mcht_str.fcode = ERROR; 50 } 51 } 21

22 umcserverprocess.c (3) 52 else if (mcht_str.fcode == DATA_REQ) { 53 if (data_process(sockfd, &mcht_str, fromaddr, *hd_ptr)) { 54 resp_mcht_str.fcode = DATA_ACK; 55 } 56 else { 57 resp_mcht_str.fcode = ERROR; 58 } 59 } 60 else if (mcht_str.fcode == LEAVE_REQ) { 61 if (leave_process(fromaddr, hd_ptr)) { 62 resp_mcht_str.fcode = LEAVE_ACK; 63 } 64 else { 65 resp_mcht_str.fcode = ERROR; 66 } 67 } 22

23 umcserverprocess.c (4) 69 if (!mk_pdu(&resp_mcht_str, &send_pdu)){ 70 fprintf(stderr, "mk_pdu ERROR!\n"); 71 return 0; } int pdu_size = sizeof(send_pdu); 76 ssize_t numbytessent = sendto(sockfd, &send_pdu, pdu_size, 0, 77 fromaddr, fromaddrlen); if (numbytessent!= pdu_size) { 80 fprintf(stderr, "sendto ERROR!\n"); 81 return 0; 82 } 83 return 1; 84 } 85 } 23

24 umcserverprocess.c (5) 86 /******************************************************************************/ 87 int join_process(mcht_t *mcht_str, struct sockaddr *fromaddr, clnt_record_t **hd_ptr) 88 { 89 clnt_record_t *new_record = (clnt_record_t *)malloc(sizeof(clnt_record_t)); if (new_record) { 92 strncpy(new_record->nickname, mcht_str->message.msg_data, 93 MAX_NAME_SIZE); 94 memcpy(&new_record->clnt_addr, fromaddr, sizeof(*fromaddr)); 95 new_record->last_atime = time(null); 96 new_record->next = *hd_ptr; 97 *hd_ptr = new_record; 98 } 99 else { 100 fprintf(stderr, "malloc ERROR!\n"); 101 return 0; 102 } return 1; 105 } 24

25 umcserverprocess.c (6) 107 /******************************************************************************/ 108 int leave_process(struct sockaddr *fromaddr, clnt_record_t **hd_ptr) 109 { 110 clnt_record_t *tmp; 111 clnt_record_t *prev = NULL; 112 int found = 0; for (tmp = *hd_ptr;!found && tmp; prev = tmp, tmp = tmp->next) { 115 if (SockAddrsEqual(&tmp->clnt_addr, fromaddr)) { 116 if (prev) 117 prev->next = tmp->next; 118 else // first one 119 *hd_ptr = tmp->next; found = 1; 122 } 123 } if (!found) { 126 fprintf(stderr, "no such client!\n"); 127 return 0; 128 } free(tmp); 131 return 1; 132 } 25

26 umcserverprocess.c (7) 133 /******************************************************************************/ 134 int data_process(int sockfd, mcht_t *mcht_str, struct sockaddr *fromaddr, 135 clnt_record_t *hd_ptr) 136 { 137 mcht_t data; clnt_record_t *tmp; 140 int found = 0; for (tmp = hd_ptr;!found && tmp; tmp = tmp->next) { 143 if (SockAddrsEqual(&tmp->clnt_addr, fromaddr)) { 144 tmp->last_atime = time(null); 145 data.fcode = MESSAGE; 146 sprintf(data.message.msg_data, "%s: ", tmp->nickname); 147 strncat(data.message.msg_data, mcht_str->message.msg_data, 148 MAX_MSG_SIZE); 149 data.message.msg_size = strlen(data.message.msg_data); 150 found = 1; 151 } 152 } if (!found) { 155 fprintf(stderr, "no such client!\n"); 156 return 0; 157 }

27 umcserverprocess.c (8) 159 mcht_pdu_t send_pdu; if (!mk_pdu(&data, &send_pdu)){ 162 fprintf(stderr, "mk_pdu ERROR!\n"); 163 return 0; 164 } 165 for (tmp = hd_ptr; tmp; tmp = tmp->next) { 166 if (SockAddrsEqual(&tmp->clnt_addr, fromaddr)) { 167 continue; 168 } 169 else { 170 int pdu_size = sizeof(send_pdu); 171 ssize_t numbytessent = sendto(sockfd, 172 &send_pdu, pdu_size, 0, 173 &tmp->clnt_addr, sizeof(tmp->clnt_addr)); if (numbytessent!= pdu_size) { 176 fprintf(stderr, "sendto ERROR!\n"); 177 return 0; 178 } 179 } 180 } 181 return 1; 182 } 27

28 umcserverprocess.c (9) 184 /******************************************************************************/ 185 int chk_alive(int sockfd, clnt_record_t *hd_ptr) 186 { 187 mcht_t alive_chk; 188 mcht_pdu_t send_pdu; alive_chk.fcode = CHK_REQ; 191 if(!mk_pdu(&alive_chk, &send_pdu)) { 192 fprintf(stderr, "mk_pdu ERROR!\n"); 193 return 0; 194 } time_t current_time = time(null); clnt_record_t *tmp; for (tmp = hd_ptr; tmp; tmp = tmp->next) { 201 if (tmp->last_atime + MAX_SILENT_TIME < current_time) { 202 int pdu_size = sizeof(send_pdu); 203 ssize_t numbytessent = sendto(sockfd, 204 &send_pdu, pdu_size, 0, 205 &tmp->clnt_addr, sizeof(tmp->clnt_addr)); if (numbytessent!= pdu_size) { 208 fprintf(stderr, "sendto ERROR!\n"); 209 return 0; 210 } 211 } 212 } 213 return 1; 214 } 28

29 umcserverprocess.c (10) 216 /******************************************************************************/ 217 int update_client_status(struct sockaddr *fromaddr, clnt_record_t *hd_ptr) 218 { 219 clnt_record_t *tmp; 220 int found = 0; for (tmp = hd_ptr;!found && tmp; tmp = tmp->next) { 223 if (SockAddrsEqual(&tmp->clnt_addr, fromaddr)) { 224 tmp->last_atime = time(null); 225 found = 1; 226 } 227 } if (!found) { 230 fprintf(stderr, "no such client!\n"); 231 return 0; 232 } return 1; 235 } 29

30 umcserverprocess.c (11) 237 /******************************************************************************/ 238 int prnt_clnt_list(clnt_record_t *hd_ptr) 239 { 240 int clnt_cnt = 0; 241 clnt_record_t *tmp; printf("client List: "); 244 for (tmp = hd_ptr; tmp; tmp = tmp->next, clnt_cnt++) { 245 PrintSocketAddress(&tmp->clnt_addr, stdout); 246 if (tmp->next) 247 printf(" - "); 248 } 249 printf("\n"); return clnt_cnt; } 30

31 umcserver.c (1) 1 #include <stdlib.h> 2 #include <string.h> 3 #include <sys/types.h> 4 #include <sys/socket.h> 5 #include <netdb.h> 6 7 #include "../../common/practical.h" 8 #include "umcprotocol.h" 9 #include "umcserverprocess.h" int prepare_udp_server_socket(char *service); 12 31

32 umcserver.c (2) 13 /******************************************************************************/ 14 int main(int argc, char *argv[]) { if (argc!= 2) // 명령어행의인자개수가알맞은지확인 17 DieWithUserMessage("Parameter(s)", "<Server Port/Service>"); char *service = argv[1]; // 첫번째인자 : 지역포트 / 서비스이름 int sock = prepare_udp_server_socket(service); clnt_record_t *head = NULL; struct sockaddr_storage clntaddr; 26 socklen_t clntaddrlen = sizeof(clntaddr); while(1) { 29 if (!recvfrom_and_serve(sock, (struct sockaddr *) &clntaddr, clntaddr Len, &head)) { 30 DieWithSystemMessage("recvfrom() failed"); 31 } 32 if (!chk_alive(sock, head)) { 33 DieWithSystemMessage("chk_alive() failed"); 34 } } 37 close(sock); 38 } 32

33 umcserver.c (3) 39 /******************************************************************************/ 40 int prepare_udp_server_socket(char *service) 41 { 42 struct addrinfo addrcriteria; // 원하는주소기준설정 43 memset(&addrcriteria, 0, sizeof(addrcriteria)); // 구조체를 0으로초기화 44 addrcriteria.ai_family = AF_UNSPEC; // IPv4,IPv6 모두반환 45 addrcriteria.ai_flags = AI_PASSIVE; // 주소 / 포트에무관하게반환 46 addrcriteria.ai_socktype = SOCK_DGRAM; // 데이터그램소켓만반환 47 addrcriteria.ai_protocol = IPPROTO_UDP; // UDP만반환 struct addrinfo *servaddr; 50 int rtnval = getaddrinfo(null, service, &addrcriteria, &servaddr); 51 if (rtnval!= 0) 52 DieWithUserMessage("getaddrinfo() failed", gai_strerror(rtnval)); int sock = socket(servaddr->ai_family, servaddr->ai_socktype, 55 servaddr->ai_protocol); 56 if (sock < 0) 57 DieWithSystemMessage("socket() failed"); if (bind(sock, servaddr->ai_addr, servaddr->ai_addrlen) < 0) 60 DieWithSystemMessage("bind() failed"); freeaddrinfo(servaddr); return sock; 65 } 33

CSE 333 Section 8 - Client-Side Networking

CSE 333 Section 8 - Client-Side Networking CSE 333 Section 8 - Client-Side Networking Welcome back to section! We re glad that you re here :) Networking Quick Review What are the following protocols used for? (bonus: what layer of the networking

More information

CSE 333 SECTION 7. Client-Side Network Programming

CSE 333 SECTION 7. Client-Side Network Programming CSE 333 SECTION 7 Client-Side Network Programming Overview Domain Name Service (DNS) Client side network programming steps and calls dig and ncat tools Network programming for the client side Recall the

More information

Client-side Networking

Client-side Networking Client-side Networking CSE 333 Autumn 2018 Instructor: Hal Perkins Teaching Assistants: Tarkan Al-Kazily Renshu Gu Trais McGaha Harshita Neti Thai Pham Forrest Timour Soumya Vasisht Yifan Xu Administriia

More information

Azblink API for Sending XMPP Messages via HTTP POST

Azblink API for Sending XMPP Messages via HTTP POST Azblink API for Sending XMPP Messages via HTTP POST Abstract: This document is to describe the API of Azblink SBC for sending XMPP messages via HTTP POST. This is intended for the systems or the devices

More information

목포해양대해양컴퓨터공학과. IPv6 적용

목포해양대해양컴퓨터공학과. IPv6 적용 IPv6 적용 1 IPV6 기본규격 2 IPv6 Basic header 3 IPv6 - Extension Headers (1) Hop-by-Hop Options (0) RSVP, PIM/MLD, etc. Routing (43) Source Routing, MIPv6 Fragment (44) Encapsulating Security Payload (50) IPsec

More information

CSE 333 SECTION 8. Sockets, Network Programming

CSE 333 SECTION 8. Sockets, Network Programming CSE 333 SECTION 8 Sockets, Network Programming Overview Domain Name Service (DNS) Client side network programming steps and calls Server side network programming steps and calls dig and ncat tools Network

More information

CSE 333 SECTION 7. C++ Virtual Functions and Client-Side Network Programming

CSE 333 SECTION 7. C++ Virtual Functions and Client-Side Network Programming CSE 333 SECTION 7 C++ Virtual Functions and Client-Side Network Programming Overview Virtual functions summary and worksheet Domain Name Service (DNS) Client side network programming steps and calls dig

More information

Network Socket Programming - 3 BUPT/QMUL

Network Socket Programming - 3 BUPT/QMUL Network Socket Programming - 3 BUPT/QMUL 2017-3-27 Agenda Basic concepts in NP Introduction to IP & TCP/UDP Introduction to Sockets 2 Introduction to Sockets Reviews of some helpful points Sockets interface

More information

CS 640: Computer Networking

CS 640: Computer Networking CS 640: Computer Networking Yu-Chi Lai Lecture 3 Network Programming Topics Client-server model Sockets interface Socket primitives Example code for echoclient and echoserver Debugging With GDB Programming

More information

Network Socket Programming - 3 BUPT/QMUL

Network Socket Programming - 3 BUPT/QMUL Network Socket Programming - 3 BUPT/QMUL 2018-04-02 Agenda Basic concepts in NP Introduction to IP & TCP/UDP Introduction to Sockets 2 Introduction to Sockets Reviews of some helpful points Sockets interface

More information

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4

The Berkeley Sockets API. Networked Systems Architecture 3 Lecture 4 The Berkeley Sockets API Networked Systems Architecture 3 Lecture 4 The Berkeley Sockets API Widely used low-level C networking API First introduced in 4.3BSD Unix Now available on most platforms: Linux,

More information

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions

Network Programming in C: The Berkeley Sockets API. Networked Systems 3 Laboratory Sessions Network Programming in C: The Berkeley Sockets API Networked Systems 3 Laboratory Sessions The Berkeley Sockets API Widely used low-level C networking API First introduced in 4.3BSD Unix Now available

More information

Network Programming in C. Networked Systems 3 Laboratory Sessions and Problem Sets

Network Programming in C. Networked Systems 3 Laboratory Sessions and Problem Sets Network Programming in C Networked Systems 3 Laboratory Sessions and Problem Sets Lab Timetable, Aims, and Objectives Teaching Week Activity 14 Introduction 15 Warm-up exercise 16 17 Web client 18 19 20

More information

CSE 333 SECTION 6. Networking and sockets

CSE 333 SECTION 6. Networking and sockets CSE 333 SECTION 6 Networking and sockets Overview Network Sockets IP addresses and IP address structures in C/C++ DNS Resolving DNS names Demos Section exercise Sockets Network sockets are network interfaces

More information

CSE 333 SECTION 7. Client-Side Network Programming

CSE 333 SECTION 7. Client-Side Network Programming CSE 333 SECTION 7 Client-Side Network Programming Overview Homework 3 due tonight Questions? Domain Name Service (DNS) Review Client side network programming steps and calls intro dig tool Network programming

More information

Fountain Multimedia Broadcasting Final Report Spring Semester 2012

Fountain Multimedia Broadcasting Final Report Spring Semester 2012 Fountain Multimedia Broadcasting Final Report Spring Semester 2012 -Full Report- By Aqeel Alhashim Ben Kappel Jassim Alhashim Prepared to partially fulfill the requirements for ECE402 Department of Electrical

More information

ENGN8637. Advanced Topics in Communications. Your Title

ENGN8637. Advanced Topics in Communications. Your Title ENGN8637 Advanced Topics in Communications Your Title Your name uxxxxxxxx@anu.edu.au Research School of Engineering, ANU submitted on 18/March/2018 Contents 1 Introduction 1 2 A New Section 3 3 Yet another

More information

CS 3516: Computer Networks

CS 3516: Computer Networks Welcome to CS 3516: Prof. Yanhua Li Time: 9:00am 9:50am M, T, R, and F Location: AK219 Fall 2018 A-term 1 Some slides are originally from the course materials of the textbook Computer Networking: A Top

More information

Elementary TCP Sockets

Elementary TCP Sockets Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens Distributed Computer Systems 1 socket interface Application 1 Application 2 socket interface user kernel user kernel

More information

CSE 333 Section 3. Thursday 12 April Thursday, April 12, 12

CSE 333 Section 3. Thursday 12 April Thursday, April 12, 12 CSE 333 Section 3 Thursday 12 April 2012 Goals for Today 1. Overview IP addresses 2. Look at the IP address structures in C/C++ 3. Overview DNS 4. Talk about how to use DNS to translate IP addresses 5.

More information

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Sockets. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Sockets Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Internet Connections (1) Connection Clients and servers communicate by sending streams of

More information

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University  Embedded Software Lab. 1 Sockets Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University http://nyx.skku.ac.kr Internet Connections (1) 2 Connection Clients and servers communicate by sending streams of bytes over

More information

Redesde Computadores(RCOMP)

Redesde Computadores(RCOMP) Redesde Computadores(RCOMP) Theoretical-Practical (TP) Lesson 06 2016/2017 Berkeley sockets API, C and Java. Address families and address storing. Basic functions/methods for UDP applications. UDP client

More information

Project 3. Reliable Data Transfer over UDP. NTU CSIE Computer Networks 2011 Spring

Project 3. Reliable Data Transfer over UDP. NTU CSIE Computer Networks 2011 Spring Project 3 Reliable Data Transfer over UDP NTU CSIE Computer Networks 2011 Spring Project Goal In Project 3, students are asked to understand and implement reliable data transfer mechanism over UDP. UDP

More information

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University

Hyo-bong Son Computer Systems Laboratory Sungkyunkwan University Sockets Hyo-bong Son (proshb@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Client-Server Model Most network application is based on the client-server model: A server

More information

ENGN4521/6521. Embedded Wireless. An LIPD Band RF Front End for DATV

ENGN4521/6521. Embedded Wireless. An LIPD Band RF Front End for DATV ENGN4521/6521 Embedded Wireless An LIPD Band RF Front End for DATV V3.0 Copyright 2014-2015 G.G. Borg College of Engineering and Computer Science. Australian National University 1 Contents 1 Foreword 3

More information

Outline. Option Types. Socket Options SWE 545. Socket Options. Out-of-Band Data. Advanced Socket. Many socket options are Boolean flags

Outline. Option Types. Socket Options SWE 545. Socket Options. Out-of-Band Data. Advanced Socket. Many socket options are Boolean flags Outline SWE 545 Socket Options POSIX name/address conversion Out-of-Band Data Advanced Socket Programming 2 Socket Options Various attributes that are used to determine the behavior of sockets Setting

More information

IP Addresses, DNS. CSE 333 Spring Instructor: Justin Hsia

IP Addresses, DNS. CSE 333 Spring Instructor: Justin Hsia IP Addresses, DNS CSE 333 Spring 2018 Instructor: Justin Hsia Teaching Assistants: Danny Allen Dennis Shao Eddie Huang Kevin Bi Jack Xu Matthew Neldam Michael Poulain Renshu Gu Robby Marver Waylon Huang

More information

Programming with TCP/IP. Ram Dantu

Programming with TCP/IP. Ram Dantu 1 Programming with TCP/IP Ram Dantu 2 Client Server Computing Although the Internet provides a basic communication service, the protocol software cannot initiate contact with, or accept contact from, a

More information

CS4700/CS5700 Fundamentals of Computer Networking

CS4700/CS5700 Fundamentals of Computer Networking CS4700/CS5700 Fundamentals of Computer Networking Prof. Alan Mislove Lecture 3: Crash course in socket programming September 10th, 2009 Project 0 Goal: Familiarize you with socket programming in C Implement

More information

PA #2 Reviews. set_name, get_name, del_name. Questions? Will be modified after PA #4 ~

PA #2 Reviews. set_name, get_name, del_name. Questions? Will be modified after PA #4 ~ Sockets Prof. Jin-Soo Kim( jinsookim@skku.edu) TA Dong-Yun Lee(dylee@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu PA #2 Reviews set_name, get_name, del_name Will

More information

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E.

UNIX Sockets. Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E. UNIX Sockets Developed for the Azera Group By: Joseph D. Fournier B.Sc.E.E., M.Sc.E.E. Socket and Process Communication application layer User Process Socket transport layer (TCP/UDP) network layer (IP)

More information

IP Addresses, DNS. CSE 333 Summer Teaching Assistants: Renshu Gu William Kim Soumya Vasisht

IP Addresses, DNS. CSE 333 Summer Teaching Assistants: Renshu Gu William Kim Soumya Vasisht IP Addresses, DNS CSE 333 Summer 2018 Instructor: Hal Perkins Teaching Assistants: Renshu Gu William Kim Soumya Vasisht Lecture Outline Network Programming Sockets API Network Addresses DNS Lookup 2 Files

More information

UNIX System Programming Lecture 19: IP Sockets

UNIX System Programming Lecture 19: IP Sockets UNIX System Programming Lecture 19: Outline Reference BLP: Chapter 15 man pages: socket, bind, connect, listen, accept, ip(7), ipv6(7), getaddrinfo, getnameinfo 1 Review of UNIX Sockets On the server,

More information

StoneGate Firewall/VPN 2.5 TECHNICAL NOTE. Server Pool Monitoring Agent Protocol

StoneGate Firewall/VPN 2.5 TECHNICAL NOTE. Server Pool Monitoring Agent Protocol StoneGate Firewall/VPN 2.5 TECHNICAL NOTE Server Pool Monitoring Agent Protocol Protocol Description This document describes the Server Pool Monitoring Agent Protocol that is used for communications between

More information

Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현

Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현 Unix Network Programming Chapter 4. Elementary TCP Sockets 광운대학교컴퓨터과학과 정보통신연구실 석사과정안중현 4.1 Introduction A Time line of the typical scenario that takes place between a TCP client and server. Describes the

More information

2007 Microsoft Corporation. All rights reserved.

2007 Microsoft Corporation. All rights reserved. Creating a Basic Winsock Application 2007 Microsoft Corporation. All rights reserved. To create a basic Winsock application 1. Create a new empty project. 2. Add an empty C++ source file to the project.

More information

Introduction to Client-Server Model

Introduction to Client-Server Model Preview Introduction to Client-Server Model Motivation of Client-Server Model Terminologies and Concepts in Client-Server Model Connectionless vs. Connection-Oriented Stateless vs. Stateful Server Identify

More information

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function NETWORK AND SYSTEM PROGRAMMING LAB 15 I/O Multiplexing: select and poll function 15.1 objectives What is a Concurrent server Use of Select System call Use of Poll System call 15.2 What is concurrent server?

More information

CSCI 4061: Sockets and Network Programming

CSCI 4061: Sockets and Network Programming 1 CSCI 4061: Sockets and Network Programming Chris Kauffman Last Updated: Tue Dec 5 13:30:56 CST 2017 Networks are Aging Source: www.ipv6now.hk Source: XKCD #865 2 3 Aging Networks Makes Network Programming

More information

How to write a Measurement Telnet Server

How to write a Measurement Telnet Server How to write a Measurement Telnet Server A measurement Telnet server allows you to access remote I/Os with a standard Telnet client program. The following samples shows a way to set the LEDs of a DNP/EVA2

More information

The exam is closed book, closed notes, closed electronics, closed telepathy, open mind.

The exam is closed book, closed notes, closed electronics, closed telepathy, open mind. Name There are 7 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes, closed

More information

Computer Network Programming

Computer Network Programming Practical Programming Computer Network Programming Marwan Burelle & David Bouchet david.bouchet.epita@gmail.com 1 Quick Overview 1.IP and Protocol Stack 2.TCP Concepts 3.Client / Server Concepts 4.Socket

More information

Socket Programming. #In the name of Allah. Computer Engineering Department Sharif University of Technology CE443- Computer Networks

Socket Programming. #In the name of Allah. Computer Engineering Department Sharif University of Technology CE443- Computer Networks #In the name of Allah Computer Engineering Department Sharif University of Technology CE443- Computer Networks Socket Programming Acknowledgments: Lecture slides are from Computer networks course thought

More information

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University Embedded Software Lab.

Sockets. Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University  Embedded Software Lab. 1 Sockets Dong-kun Shin Embedded Software Laboratory Sungkyunkwan University http://nyx.skku.ac.kr Echo Client (1) 2 #include #include #include #include

More information

#include <sys/socket.h> int listen(int socket, int backlog); socket. socket. backlog

#include <sys/socket.h> int listen(int socket, int backlog); socket. socket. backlog connection listener #include int listen(int socket, int backlog); socket socket backlog #include int accept(int socket, struct sockaddr *addr, socklen_t *addr_len); socket

More information

Programming Internet with Socket API. Hui Chen, Ph.D. Dept. of Engineering & Computer Science Virginia State University Petersburg, VA 23806

Programming Internet with Socket API. Hui Chen, Ph.D. Dept. of Engineering & Computer Science Virginia State University Petersburg, VA 23806 Programming Internet with Socket API Hui Chen, Ph.D. Dept. of Engineering & Computer Science Virginia State University Petersburg, VA 23806 10/19/2015 CSCI 445 - Fall 2015 1 Acknowledgements Some pictures

More information

CS321: Computer Networks Socket Programming

CS321: Computer Networks Socket Programming CS321: Computer Networks Socket Programming Dr. Manas Khatua Assistant Professor Dept. of CSE IIT Jodhpur E-mail: manaskhatua@iitj.ac.in Socket Programming It shows how the network application programs

More information

Chapter 16. Network IPC: Sockets

Chapter 16. Network IPC: Sockets Chapter 16. Network IPC: Sockets System Programming http://www.cs.ccu.edu.tw/~pahsiung/courses/sp 熊博安國立中正大學資訊工程學系 pahsiung@cs.ccu.edu.tw Class: EA-104 (05)2720411 ext. 33119 Office: EA-512 Textbook: Advanced

More information

The BSD UNIX Socket Interface (CS 640 Lecture) Assignment 1. Interprocess Communication (IPC) Work Individually (no groups)

The BSD UNIX Socket Interface (CS 640 Lecture) Assignment 1. Interprocess Communication (IPC) Work Individually (no groups) The BSD UNIX Socket Interface (CS 640 Lecture) Assignment 1 Work Individually (no groups) Due Date: in class, Monday, September 19 Robert T Olsen olsen@cswiscedu 7390CS Office Hours: 3-5T, 11-12F - exception

More information

Write your answer on the next page. You may remove this page for reference while working if you wish.

Write your answer on the next page. You may remove this page for reference while working if you wish. Question 1. (20 points) A bit of C++ hacking STL version The question that is a lot longer than the answer. It s a social media world and Twitter wants you to digest some data that they have. Write a program

More information

Network Programming Worksheet 2. Simple TCP Clients and Servers on *nix with C.

Network Programming Worksheet 2. Simple TCP Clients and Servers on *nix with C. Simple TCP Clients and Servers on *nix with C. Aims. This worksheet introduces a simple client and a simple server to experiment with a daytime service. It shows how telnet can be used to test the server.

More information

Piotr Mielecki Ph. D.

Piotr Mielecki Ph. D. Piotr Mielecki Ph. D. http://mielecki.ristel.pl/ piotr.mielecki@pwr.edu.pl pmielecki@gmail.com Building blocks of client-server applications: Client, Server, Middleware. Simple client-server application:

More information

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science NETWORK PROGRAMMING CSC- 341 25 Instructor: Junaid Tariq, Lecturer, Department of Computer Science 26 9 Lecture Sockets as means for inter-process communication (IPC) application layer Client Process Socket

More information

Communication Networks ( ) / Spring 2011 The Blavatnik School of Computer Science, Tel-Aviv University. Allon Wagner

Communication Networks ( ) / Spring 2011 The Blavatnik School of Computer Science, Tel-Aviv University. Allon Wagner Communication Networks (0368-3030) / Spring 2011 The Blavatnik School of Computer Science, Tel-Aviv University Allon Wagner Staff Lecturer: Dr. Eliezer Dor eliezer.dor @ gmail Office hours: by appointment

More information

Network Programming Week #1. K.C. Kim

Network Programming Week #1. K.C. Kim Network Programming Week #1 K.C. Kim kckim@konkuk.ac.kr How do we communicate? Mail Example 1. Write a mail 2. Put the mail into a mailbox 3. Post office classify mails based on the address 4. Cars, airplanes

More information

1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter

1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter 1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter 2004. 3 http://www.sfu.ca/~vwchu 4 chuvincent (at) gmail (dot) com 5 */ 6 7 #define closesocket

More information

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013

Processes communicating. Network Communication. Sockets. Addressing processes 4/15/2013 Processes communicating Network Communication Process: program running within a host. within same host, two processes communicate using inter-process communication (defined by OS). processes in different

More information

CS 4400 Fall 2017 Final Exam Practice

CS 4400 Fall 2017 Final Exam Practice CS 4400 Fall 2017 Final Exam Practice Name: Instructions You will have eighty minutes to complete the actual open-book, opennote exam. Electronic devices will be allowed only to consult notes or books

More information

Redes de Computadores (RCOMP)

Redes de Computadores (RCOMP) Redes de Computadores (RCOMP) Theoretical-Practical (TP) Lesson 07 2017/2018 Berkeley sockets API, C and Java. Basic functions/methods for TCP applications. TCP client and server. Asynchronous reception.

More information

Dept. of Computer Science & Engineering 1 Knowledge & Data Engineering Lab.

Dept. of Computer Science & Engineering 1 Knowledge & Data Engineering Lab. Socket Programming Dept. of Computer Science & Engineering 1 Socket A socket is a communication end point. Is equivalent to a computer s network (hardware) interface. Allows a network application to plug

More information

CSE 124 Discussion Section Sockets Programming 10/10/17

CSE 124 Discussion Section Sockets Programming 10/10/17 CSE 124 Discussion Section Sockets Programming 10/10/17 Topics What s a socket? Creating a socket Connecting a socket Sending data Receiving data Resolving URLs to IPs Advanced socket options Live code

More information

Ά η η 1 (30%): Sockets. socket () bind () listen () accept () connect () read () write () close ()

Ά η η 1 (30%): Sockets. socket () bind () listen () accept () connect () read () write () close () ΗΜΥ 316 - Ε α η ια ή Ά η η 5 Υ ο οίη η Π ω ο ό ο α η αι α α ο ή sockets Ά η η 1 (30%): Sockets π α α α α α π πα π α α ω sockets Unix/Linux. Γ α α α π π α π α Server α Client π π π α έ Α π, α α απ π ω.

More information

chat.h #ifndef _CHAT_H #define _CHAT_H #define LBUFFSIZE 128 #define CBUFFSIZE 331

chat.h #ifndef _CHAT_H #define _CHAT_H #define LBUFFSIZE 128 #define CBUFFSIZE 331 chat.h #ifndef _CHAT_H #define _CHAT_H #define LBUFFSIZE 128 #define CBUFFSIZE 331 #define INCRSLOT(V) { \ ++(V) ; \ if ((V) >= CBUFFSIZE) \ (V) = 0 ; \ enum Lstates {UNUSED, MESSAGE ; struct linebuff

More information

MSc Integrated Electronics Networks Assignment. Investigation of TCP/IP Sockets and Ports. Gavin Cameron

MSc Integrated Electronics Networks Assignment. Investigation of TCP/IP Sockets and Ports. Gavin Cameron MSc Integrated Electronics Networks Assignment Investigation of TCP/IP Sockets and Ports Gavin Cameron Introduction TCP and IP (Transmission Control Protocol / Internet Protocol) are two protocols from

More information

Redesde Computadores(RCOMP)

Redesde Computadores(RCOMP) Redesde Computadores(RCOMP) Theoretical-Practical (TP) Lesson 07 2016/2017 Berkeley sockets API, C and Java. Basic functions/methods for TCP applications. TCP client and server. Asynchronous reception.

More information

Communication Networks ( ) / Fall 2013 The Blavatnik School of Computer Science, Tel-Aviv University

Communication Networks ( ) / Fall 2013 The Blavatnik School of Computer Science, Tel-Aviv University Communication Networks (0368-3030) / Fall 2013 The Blavatnik School of Computer Science, Tel-Aviv University Allon Wagner Staff Lecturer: Prof. Hanoch Levy hanoch @ cs tau Office hours: by appointment

More information

NETWORK AND SYSTEM PROGRAMMING

NETWORK AND SYSTEM PROGRAMMING NETWORK AND SYSTEM PROGRAMMING LAB 16 ELEMENTARY UDP SOCKETS The UDP protocol is connectionless and adds unreliability to the application. Each packet that is sent by the client or server is not acknowledged

More information

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems Deep C Multifile projects Getting it running Data types Typecasting Memory management Pointers Fabián E. Bustamante, Fall 2004 Multifile Projects Give your project a structure Modularized design Reuse

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function Grade: / 20 Lab Exam 1 D500 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return 0? Answer: Anything that is not a floating point number such as 4.567 or

More information

Socket Programming. What is a socket? Using sockets. Types (Protocols) Associated functions Styles

Socket Programming. What is a socket? Using sockets. Types (Protocols) Associated functions Styles Socket Programming What is a socket? Using sockets Types (Protocols) Associated functions Styles We will look at using sockets in C Note: Java and C# sockets are conceptually quite similar 1 What is a

More information

SOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program, which includes three function definitions, including the main function.

SOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program, which includes three function definitions, including the main function. (i) (6 pts.) SOFTWARE Ph.D. Qualifying Exam Spring 2017 Consider the following C program, which includes three function definitions, including the main function. #include #include

More information

// print product names in alphabetical order with total // number sold of each product using format name: total void PrintTotals();

// print product names in alphabetical order with total // number sold of each product using format name: total void PrintTotals(); Question 1. (22 points) STL and C++ classes. Our friends who run the SnackOverflow concession are writing a small program to keep track of the number of items sold. A Sales object contains a

More information

Chapter 6. The Transport Layer. Transport Layer 3-1

Chapter 6. The Transport Layer. Transport Layer 3-1 Chapter 6 The Transport Layer Transport Layer 3-1 Transport services and protocols provide logical communication between app processes running on different hosts transport protocols run in end systems

More information

NETWORK AND SYSTEM PROGRAMMING

NETWORK AND SYSTEM PROGRAMMING NETWORK AND SYSTEM PROGRAMMING LAB 09 Network Byte Ordering, inet_aton, inet_addr, inet_ntoa Functions Objectives: To learn byte order conversion To understand inet-aton, inet_addr, inet_ntoa Functions

More information

1.2 The first Internet (i.e., one of the first packet switched networks) was referred to as the ARPANET.

1.2 The first Internet (i.e., one of the first packet switched networks) was referred to as the ARPANET. CPSC 360 Spring 2011 Exam 1 Solutions This exam is closed book, closed notes, closed laptops. You are allowed to have one 8.5x11 sheets of paper with whatever you like written on the front and back. You

More information

Winsock Server adding Multiple clients support C++

Winsock Server adding Multiple clients support C++ Winsock Server adding Multiple clients support C++ This is very simple version to add multiple connection support to your server project. Here we are going to use ioctlsocket to make it non blocking and

More information

Application Programming Interfaces

Application Programming Interfaces Application Programming Interfaces Stefan D. Bruda Winter 2018 SYSTEM CALLS Machine 1 Machine 2 Application 1 Application 3 Application 4 Application 5 Application 2 API (system functions) API (system

More information

CSC209H Lecture 10. Dan Zingaro. March 18, 2015

CSC209H Lecture 10. Dan Zingaro. March 18, 2015 CSC209H Lecture 10 Dan Zingaro March 18, 2015 Creating a Client To create a client that can connect to a server, call the following, in order: socket: create a communication endpoint This is the same as

More information

PRINCIPLES OF OPERATING SYSTEMS

PRINCIPLES OF OPERATING SYSTEMS PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)

More information

Raising the Datagram API to Support Transport Protocol Evolution

Raising the Datagram API to Support Transport Protocol Evolution Raising the Datagram API to Support Transport Protocol Evolution Tom Jones, Gorry Fairhurst University of Aberdeen Colin Perkins University of Glasgow Presentation given at the IFIP Networking 2017 Workshop

More information

TCP/IP Sockets in C: Practical Guide for Programmers. Computer Chat. Internet Protocol (IP) IP Address. Transport Protocols. Ports

TCP/IP Sockets in C: Practical Guide for Programmers. Computer Chat. Internet Protocol (IP) IP Address. Transport Protocols. Ports TCP/IP Sockets in C: Practical Guide for Programmers Computer Chat! How do we make computers talk? Michael J. Donahoo Kenneth L. Calvert Morgan Kaufmann Publisher $14.95 Paperback! How are they interconnected?

More information

How to write a Measurement Telnet Server

How to write a Measurement Telnet Server How to write a Measurement Telnet Server A measurement Telnet server allows you to access remote I/Os with a standard Telnet client program. The following samples shows a way to set the LEDs of a DNP/EVA1

More information

CS321: Computer Networks Introduction to Application Layer

CS321: Computer Networks Introduction to Application Layer CS321: Computer Networks Introduction to Application Layer Dr. Manas Khatua Assistant Professor Dept. of CSE IIT Jodhpur E-mail: manaskhatua@iitj.ac.in Basic Application layer provides services to the

More information

Unix Network Programming

Unix Network Programming Introduction to Computer Networks Polly Huang EE NTU Unix Network Programming The socket struct and data handling System calls Based on Beej's Guide to Network Programming 1 The Unix Socket A file descriptor

More information

ECE322 Systems Programming Project 2: Networking with Matrix Multiplication in C Grant Kimes 12/16/15

ECE322 Systems Programming Project 2: Networking with Matrix Multiplication in C Grant Kimes 12/16/15 ECE322 Systems Programming Project 2: Networking with Matrix Multiplication in C Grant Kimes 12/16/15 This project take two inputted matrices of a given size to multiply. The client sends the data to a

More information

Introduction to Lab 2 and Socket Programming. -Vengatanathan Krishnamoorthi

Introduction to Lab 2 and Socket Programming. -Vengatanathan Krishnamoorthi Introduction to Lab 2 and Socket Programming -Vengatanathan Krishnamoorthi Before we start.. Soft deadline for lab 2- February 13 Finish assignment 1 as soon as possible if you have not yet. Hard deadline

More information

04 Elementary. Client/Server. CEN 463 Network Programming. Dr. Mostafa Hassan Dahshan. King Saud University

04 Elementary. Client/Server. CEN 463 Network Programming. Dr. Mostafa Hassan Dahshan. King Saud University CEN 463 Network Programming 04 Elementary TCP Sockets Dr. Mostafa Hassan Dahshan College of Computer and Information Sciences King Saud University Elementary TCP Client/Server 2 socket Function First function

More information

Sockets. 1 Introduction. (Reference:, Gray Chapter 10) Network Programming Lecture Notes by. Turhan TUNALI

Sockets. 1 Introduction. (Reference:, Gray Chapter 10) Network Programming Lecture Notes by. Turhan TUNALI Sockets (Reference:, Gray Chapter 10) Network Programming Lecture Notes by 1 Introduction Turhan TUNALI Unix uses a common interface for the access of files and devices that reside on a single host. The

More information

Category: Informational J. Bound J. McCann Hewlett-Packard W. Stevens February 2003

Category: Informational J. Bound J. McCann Hewlett-Packard W. Stevens February 2003 Network Working Group Request for Comments: 3493 Obsoletes: 2553 Category: Informational R. Gilligan Intransa, Inc. S. Thomson Cisco J. Bound J. McCann Hewlett-Packard W. Stevens February 2003 Status of

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

CSE 333 Lecture 16 - network programming intro

CSE 333 Lecture 16 - network programming intro CSE 333 Lecture 16 - network programming intro Hal Perkins Department of Computer Science & Engineering University of Washington Today Network programming - dive into the Berkeley / POSIX sockets API -

More information

Socket Programming. Dr. -Ing. Abdalkarim Awad. Informatik 7 Rechnernetze und Kommunikationssysteme

Socket Programming. Dr. -Ing. Abdalkarim Awad. Informatik 7 Rechnernetze und Kommunikationssysteme Socket Programming Dr. -Ing. Abdalkarim Awad Informatik 7 Rechnernetze und Kommunikationssysteme Before we start Can you find the ip address of an interface? Can you find the mac address of an interface?

More information

EEC-484/584 Computer Networks

EEC-484/584 Computer Networks EEC-484/584 Computer Networks Lecture 15 wenbing@ieee.org (Lecture nodes are based on materials supplied by Dr. Louise Moser at UCSB and Prentice-Hall) Outline 2 Review of last lecture The network layer

More information

CS4514 B08 HELP Session 1

CS4514 B08 HELP Session 1 CS4514 B08 HELP Session 1 Presented by Choong-Soo Lee clee01@cs.wpi.edu CS4514 TCP/IP Socket Programming Outline Project 1 Overview Unix Network Programming TCP Client TCP Server Processing commands How

More information

CS307 Operating Systems Processes

CS307 Operating Systems Processes CS307 Processes Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2018 Process Concept Process a program in execution An operating system executes a variety of

More information

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State

Processes. Process Concept. The Process. The Process (Cont.) Process Control Block (PCB) Process State CS307 Process Concept Process a program in execution Processes An operating system executes a variety of programs: Batch system jobs Time-shared systems user programs or tasks All these activities are

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information