1 / 13

Homework Assignment #3

Homework Assignment #3. Multithread Application. Homework Assignment #3: Multithread Application. In this work, you should make a application similar to FTP server/client, and it can be accept several user requests at the same time. Use the pthread library for multithreading.

dore
Download Presentation

Homework Assignment #3

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. Homework Assignment #3 Multithread Application

  2. Homework Assignment #3: Multithread Application • In this work, you should make a application similar to FTP server/client, and it can be accept several user requests at the same time. • Use the pthread library for multithreading

  3. About pthread • Functions: • pthread_create( pthread_t* child, pthread_attr_t* attr, void*(*fn)(void*), void* arg)) • Establish thread • pthread_exit(…) • Exit thread • pthread_join(…) • Waiting thread to complete

  4. About pthread(cont.) • Ex: Void *thread_func(void *arg) { /* do whatever a child does */ } pthread_t thread; pthread_create(&thread,NULL,thread_func,(void *)message)

  5. Flowchart_Server Start Setup your own port: #define MYPORT 9999 addr.sin_port=htons(MYPORT); Establish socket accept function will return a new socket description Ex. int clientsd; clientsd=accept (…..,….,….); You can pass the clientsd to pthread_create() And then In the thread, you can operator read/write to this socket Establish bind Establish listen Establish accept

  6. Flowchart_Server (cont.) Header: #include <pthread.h> Define: int pthread_create(pthread_t* child, pthread_attr_t* attr, void*(*fn)(void*), void* arg) Thread create Read/Write file loop fopen() / fcolse() :open/close file fread() / fwrite() : read/write file from/to buffer read() / write() : read/write buffer from/to socket feof() : check file end Thread exit Socket close

  7. Flowchart_Client Start Setup your own port: #define MYPORT 9999 addr.sin_port=htons(MYPORT); The same to the server side Establish socket Establish connect Read/Write file Socket close

  8. Executable Command • Ex. • #myserver Socket create… Socket bind to 0.0.0.0:9999 Listening on server socket… Ready to accept incoming connection… 140.120.15.125:32708 accepted 140.120.15.125 getting file “test”… ----------------------------------------------- Ready to accept incoming connection… 140.120.15.124:32741 accepted 140.120.15.124 getting file “test”… -----------------------------------------------

  9. Executable Command(cont.) • Ex. • #myclient 140.120.15.125 Socket create… Socket connect to 140.120.15.125:9999 getting file “test”…

  10. Turn In • Source code • Executing result (snapshot)

  11. Turn In (cont.) • Deadline • 23:59, Jun ,13 2006 • Ftp • IP:140.120.15.123 2222 • Username/Password: comm94/comm94 • Filename • HW3_ID.doc eg.HW3_79356001.doc • If you want to update • HW3_ID_new1.doc, HW3_ID_new2.doc …etc

  12. Turn In (cont.) • No late work is acceptable • You get zero if you miss the due day • No cheat work is acceptable • You get zero if you copy other people’s version

  13. Reference • Linux C/C++ 網路程式設計,金禾 • Linux C 函式庫參考手冊,旗標 • Linux Socket Programming,碁峰

More Related