1 / 7

Network Programming Week #7

Network Programming Week #7. J.P. Yoo willow@konkuk.ac.kr. Server only serves clients. Client-Server Model. Simple Server-Client Model. Server-Multiple Client Model. Server. Server. accept(). accept(). servsock. clntsock1. clntsock2. servsock. clntsock. Hello->. accept(). Hello->.

caspar
Download Presentation

Network Programming Week #7

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Network ProgrammingWeek #7 J.P. Yoo willow@konkuk.ac.kr

  2. Server only serves clients

  3. Client-Server Model Simple Server-Client Model Server-Multiple Client Model Server Server accept() accept() servsock clntsock1 clntsock2 servsock clntsock Hello-> accept() Hello-> Hello-> send()/recv() send()/recv() Hello-> connect() send()/recv() Hello-> connect() connect() Hello-> Client Client1 Client2 sock sock sock To Client2 : Hello

  4. Handling multiple client TCP Server • Server socket model using ‘select()’ Socket() bind() select() init-game (new socket) In-game (existing socket) Which Socket? accept() PasstoThe OtherClient() init_game()

  5. int nfds; fd_set read_fds; int num_client = 0; /* 게임 참가자 수 */ int servsock, clientsock, clientsock1, clientsock2; listen(servsock, 5); nfds = servsock + 1; FD_ZERO(&read_fds); for(;;) { FD_SET(servsock, &read_fds); /* 서버 등록 */ if((num_client==1) { FD_SET( clientsock1, &read_fds); select(nfds+1, &read_fds, null, null, null); } if((num_client==2) { FD_SET( clientsock2, &read_fds), select(nfds+2, &read_fds, null, null, null); } else select(nfds, &read_fds, null, null, null); if(FD_ISSET(servsock, &read_fds)) { /* init_game */ clientsock = accept(s, (struct sockaddr *)&client_addr, &clilen); if(num_client==0) { clientsock1=clientsock; send(clientsock1,”wait for the other player to connect!!”); num_client++; } if(num_client==1){ clientsock2=clientsock; num_client++; send(clientsock1,”start game!”); send(clientsock2,”start game!”); } } if(FD_ISSET(clientsock1, &read_fds)) { /* in_game */ recv(clientsock1); send(clientcsock2); } if(FD_ISSET(clientsock2, &read_fds)) { /* in_game */ recv(clientsock2); send(clientcsock1); } }

  6. Assignment #8 • 과제 개요 • Client-Client 하나의 쌍이 하나의 세션을 이루어 게임을 하도록 수정하라. • Server는 게임에 관여하지 않으며 두 Client의 메시지를 relay하는 역할을 수행한다. • 단 Client간 비동기 채팅 및 게임이 구현되어야 한다. • 10/22일까지 message flow와 함께 제출.. • challenge • 한 쌍의 게임 진행 중에 한 쌍의 게임을 더 만들어보자. • 두 쌍의 게임이 동시에 진행이 되는지 안 되는지 확인해보자. • 안 된다면 왜 안 되는지 해결방법은 무엇이 있을지 토의해보자.

  7. Final Project 공지 • 10월 26일(금요일) 수업 전까지 Project 계획서 제출 • 계획서 내용 • 프로젝트 개요, 특징, 시스템 구조도를 포함하여 ppt 3~5장 내외로 작성 • 버클리 소켓, WinSock에 기반한 어떠한 응용도 가능 • 개인프로젝트 • 창의성과 기술적 난이도에 따라 만점 책정

More Related