Presentation is loading. Please wait.

Presentation is loading. Please wait.

Operating System Multiple Access Chatting Program using Multithread

Similar presentations


Presentation on theme: "Operating System Multiple Access Chatting Program using Multithread"— Presentation transcript:

1 Operating System Multiple Access Chatting Program using Multithread
Han Jun Bae Korea University

2 Project purpose Main purpose of this Project Understand Thread
Develop to linux through C programming Enable to test on one computer (IP – ) client1 server client2 client3

3 Function of socket program
Function of program Server program Relay to chatting message between client and client. Enable to network connect many clients at the same time using multithread. Every message should be delivered to every connected client. Cilent program Should be able to connect to the server when you input the server IP and PORT. This program is able to input the message and output the message received from server. You can programming it if you know how to use the network related socket function even if you don’t have the enough knowledge about network.

4 Configuration of server and client
Purchase phone Assigned phone number Listening Pick up the phone Conversation End of conversation Purchase phone Make a call Conversation End of conversation Connection request Transmitting and receiving data Connection determination

5 Multithread through chatting program
Client1 Server Client2 Read Read Read Write Write Write Received messages from the client is sent to all clients. Send message.

6 pthread #include <pthread.h> Compile in Linux
To use the pthread function, you should be declare the header file. Compile in Linux gcc –c [compile target].c gcc –pthread –o [output file name] [compile target].c -pthread command connects library to use thread. ./server.o ./client.o

7 pthread int pthread_create( pthread_t *th_id, const pthread_attr_t *attr, void* 함수명, void *arg ); pthread 생성 첫 번째 인자 : pthread 식별자로 thread가 성공적으로 생성되면 thread 식별값이 주어진다. 두 번째 인자 : pthread 속성(옵션), 기본적인 thread 속성을 사용할 경우 NULL 세 번째 인자 : pthread로 분기할 함수. 반환값이 void* 타입이고 매개변수도 void* 으로 선언된 함수만 가능하다. ex) void* handler (void* arg) { ... } 네 번째 인자 : 분기할 함수로 넘겨줄 인자값. 어떤 자료형을 넘겨줄 지 모르기 때문에 void형으로 넘겨주고 상황에 맞게 분기하는 함수내에서 원래의 자료형으로 캐스팅해서 사용하면 된다. 리턴 값 : 성공적으로 pthread가 생성될 경우 0 반환

8 pthread int pthread_join( pthread_t th_id, void** thread_return );
특정 pthread가 종료될 때까지 기다리다가 특정 pthread가 종료시 자원 해제시켜준다. 첫 번째 인자 : 어떤 pthread를 기다릴 지 정하는 식별자 두 번째 인자 : pthread의 return 값, 포인트로 값을 받아오는 점을 주의할 것 int pthread_detach( pthread_t th_id ); th_id 식별자를 가지는 pthread가 부모 pthread로부터 독립한다. 즉 이렇게 독립된 pthread는 따로 pthread_join()이 없어도 종료시 자동으로 리소스 해제된다.

9 example

10 Project Due date : November 29(wednesday)
Multiple access chatting program using multithread Both client and server should be able to send and receive messages to each other. Program should be contain concept of multithread. A code file [filename.c] : 60% ex) server.c, client.c Include detailed comments inside your code

11 Project A word / hwp document that describes your program : 40%
File name is your student number. ex) doc You can use any word program. You should be explain your program in detail. All the files are compressed into one file (ex: zip) Submit your zip file to If you have any question, please mail me or use bulletin board in laboratory homepage( or visit to laboratory(engineering bldg #236)


Download ppt "Operating System Multiple Access Chatting Program using Multithread"

Similar presentations


Ads by Google