1 / 36

Monkey Talk Design and Implementation of Netmeeting-Based Network Service Using Socket Programming

Monkey Talk Design and Implementation of Netmeeting-Based Network Service Using Socket Programming. Speaker : 簡祥任 何政儒 Date : 2006.06.26 Est. Time : 20 minutes. UNIX Project (0936) 2006 Spring Department of CSIE, TungHai University. I NTRODUCTION. Server Daemon - MonkeyD MonkeyTalk Client

alea-durham
Download Presentation

Monkey Talk Design and Implementation of Netmeeting-Based Network Service Using Socket Programming

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. Monkey TalkDesign and Implementation of Netmeeting-Based Network Service Using Socket Programming Speaker : 簡祥任 何政儒 Date : 2006.06.26 Est. Time : 20 minutes UNIX Project (0936) 2006 Spring Department of CSIE, TungHai University

  2. INTRODUCTION • Server Daemon - MonkeyD • MonkeyTalk Client • Command Line Interface (CLI) Version • Graphic User Interface (GUI) Version

  3. INTRODUCTION • Server Daemon • Run in background (daemon mode) or foreground (verbose mode) • Log events • Provide chatting environment • Accept connection • Collect users’ data • Handle request from client • Broadcast messages

  4. INTRODUCTION • Client – CLI • Interpret user commands • QUIT, HELP, etc. • Connect to host • Using TCP Socket and IPv4 Protocol • Resolve domain name (lookup DNS) • Open new chat room • Join a opened chat room • Chat in room

  5. INTRODUCTION • Client – GUI • Provide the same functions as CLI version does • Construct graphic interfaces using Qt library

  6. INTRODUCTION • Development Environment • Operating System • Fedora 3 (kernel 2.6.8) • Mandrake Linux 10.0 (kernel 2.6.3) • Window Environment • Provided by XFree86 via X11R6 protocol • Window Manager: KDE 3.2 • Compilation • GNU Compiler Collection (3.3.2) with thread support • Trolltech Qt Library (3.2.3) and Qmake utility (1.06c)

  7. INTRODUCTION • Operating System Dependents • TCP Module • achieve the communication between server and clients • Qt Library / X11 Server • Construct GUI • Pthread Library

  8. DESIGN • Key Methodologies • Application-Layer Protocol • Multi-Threading • States Transition and Control • Qt Programming

  9. Application-Layer Protocol • Language that server and clients talks • The interactions between server and clients are achieved by sending messages • One message is a string of ASCII characters in variable length and ends up with a new-line character (ASCII=13) • Composed of two fields: OPCODE and ARGUMENT • OPCODE • fixed length with four characters • specify which command is in use • ARGUMENT • variable length • may be absent in some commands

  10. Application-Layer Protocol • Three formats of message • No ARGUMENT • Single ARGUMENT • Multiple ARGUMENT • arguments are separated by a colon character “:”

  11. Application-Layer Protocol • We’ve designed sixteen commands for different purposes

  12. Application-Layer Protocol • Example • ULST: client request list of all users • UADD: server return information of online users Client: ULSTServer: UADD 0:John:1:Room#1Server: UADD 1:Tom:2:Room#2Server: UADD 2:Sam:2:Room#2Server: UADD

  13. Multi-Threading • Server process… • Serve many clients via different connections simultaneously • How about using fork() to fork folks to serve each client? • Unfortunately, fork() is a slow system call and IPC (shared-memory) of spawned process consume much resource • Send messages while receiving message • Process got blocked after calling read() – blocked I/O system call • Can be solved by replacing with non-blocked I/O system calls or threading • Client process… • Receiving command from user and message from host at the same time

  14. Multi-Threading • Threading Model • Client threads • BananaEater • Receive message • BananaFeeder • get input from user • send messages • Server threads • Main thread • accept connections • create new user • Pair of BananaEater and BananaFeeder for each client

  15. Multi-Threading • Broadcast messages • Server main thread • create user profile when new connection has established • MesgIndex, one of the fields in user profile, contains the index of next message to be sent in queue • Server BananaEater thread • initialize MesgIndex when client has entered room • insert received message to message queue • Server BananaFeeder thread • check if the value of MesgIndex is equal to current index of message queue on a regular basis (busy polling) • send new arrival message to client and increase MesgIndex by one while MesgIndex is not equal to current index

  16. Multi-Threading • Broadcast messages • User entered Room#2

  17. Multi-Threading • Broadcast messages • New message has arrived

  18. Multi-Threading • Broadcast messages • BananaFeeder send new message to user and update MesgIndex

  19. Multi-Threading • Race Conditions • Occurs in server process • Threads write and read to shared data in race • Consistence of data could be damaged in such situation • Solution: Using mutual exclusive (MUTEX) lock to protect shared data • Call pthread_mutex_lock() before accessing shared data • Call pthread_mutex_unlock later • Threads never access to shared data in chorus

  20. State Transition and Control • Flow Control • Server and client process should handle improper use of commands • Ex. Client send ULST before NICK • Ex. User use EXIT command before connecting to host • Fifteen states has been defined

  21. State Transition and Control

  22. Qt Programming • Client – GUI Version • Use Qt library to construct graphical interface • Developed by using Qt Designer • Each “window” has own class, derived from QWidget • Events are caught and handled by signal-slot mechanism • All events handling written in <main.cpp>

  23. Qt Programming

  24. Qt概論 • 以C++為基礎所開發針對GUI設計的程式函式庫 • 能使用Qt Designer輕鬆設計出介面,或自己撰寫程式。

  25. Qt Object Model • signals and slots • object properties • events and event filters • contextual string translation for internationalization • sophisticated interval driven timers • object trees • guarded pointers, QGuardedPtr

  26. Object Properties • 分為Q_PROPERTY和Q_OVERRIDE,繼承至QObject • Q_PROPERTY : // QButton *b and QObject *o point to the same button b->setDown( TRUE ); o->setProperty( "down", TRUE ); • 提升compile time的效能

  27. Events and Event Filters • events是一個物件繼承至QEvent, 例如:QPaintEvent、QMouseEvent、QKeyEvent等 • QObject::installEventFilter():用於外部event的參考

  28. Signals and Slots • Signals:當object想改變內部狀態時所發出的一種訊息,就是signal, Ex:JPushButton中的clicked()。 • Slots: 只有當signal connected被發出時,才會被使用,是一種C++ functions。 • Ex: connect(&a, SIGNAL(clicked()), &b, SLOT(clear( ));

  29. Qt 運作原理 • Qt 是屬於多平台型的函式庫 • Ex:X11

  30. 實做 • Qt Designer :

  31. Qt Programming • References • Official online documentation • http://doc.trolltech.com/3.3/ • Qt 3.3 Whitepaper, Trolltech • C++ GUI Programming with Qt 3 • By Jasmin Blanchette, Mark Summerfield, Prentice Hall • Free to download now! • Programming with Qt • By Matthias Kalle Dalheimer 2nd edition, O'Reilly Media

More Related