复旦大学:《计算机网络 Computer Networking》课程实验指导_因特网中继聊天(IRC)服务器_socketProgramming-Part2

Socket Programming Part 2 Sop, Fan 07302010028@fudan.edu.cn Reference: Daniel Spangenberger Computer Networks PPT-4 Socket Programming
Sop, Fan 07302010028@fudan.edu.cn Reference: Daniel Spangenberger Computer Networks PPT-4 Socket Programming

Topics ° Concurrency review Why should we use∴? Our experiences? Socket Programming related System requirement(robustness. How to cooperate with socket AP[? ° Example How to modify the example to fit further requirement?
Concurrency Review Why should we use …? Our experiences? Socket Programming related System requirement(robustness…) How to cooperate with socket API? Example How to modify the example to fit further requirement?

A scenario。。 Clients Server User 1 connect() accept( fgets() (goes to lunch Blocks read() User connect( Blocked
Clients User 1 (goes to lunch) Server connect() accept() fgets() User 2 read() connect() Blocked! Blocks!

How did we add concurrency Processes Uses forko Easy to understand(actually we have implemented one version A lot to consider about causing complexity(zombie, syscall.) e Threads Natural concurrency (new thread per connection) Easier to understand you know it already) Complexity is increased(possible race conditions) Use non- blocking I/O Uses select () Explicit control flow(no race conditions Explicit control flow more complicated though
Processes Uses fork() Easy to understand(actually we have implemented one version!) A lot to consider about causing complexity(zombie, syscall…) Threads Natural concurrency (new thread per connection) Easier to understand (you know it already) Complexity is increased (possible race conditions) Use non-blocking I/O Uses select() Explicit control flow (no race conditions!) Explicit control flow more complicated though

Multi-process Forko Use Pid to verify different process Assign different task flow accordingly Signal& waitpid(…) Tracing child processes, kill the zombies e Other process control methods?
Fork() Use Pid to verify different process Assign different task flow accordingly Signal & waitpid(…) Tracing child processes, kill the zombies Other process control methods?

Multi-thread ° pthread create Create thread according to detailed settings Pthread(series: join, detach, canceL.) Imply different polices other thread control methods
pthread_create Create thread according to detailed settings Pthread(series: join, detach, cancel…) Imply different polices. Other thread control methods?

lO Multiplexing Monitor sockets with select( int select(int maxed fd set *readfds, fd set *writefds, fd set *exceptfds, const struct timespec *timeout)i ● So what' san fd set? Bit vector with FD setsize bits maxed- Max file descriptor+1 readfs-Bit vector of read descriptors to monitor writefds -Bit vector of write descriptors to monitor exceptfds -Read the manpage, set to NULL timeout-How long to wait with no activity before returning, NULI for eternity
Monitor sockets with select() int select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timespec *timeout); So what’s an fd_set? Bit vector with FD_SETSIZE bits maxfd – Max file descriptor + 1 readfs – Bit vector of read descriptors to monitor writefds – Bit vector of write descriptors to monitor exceptfds – Read the manpage, set to NULL timeout – How long to wait with no activity before returning, NULL for eternity

So what about bit vectors? e void Fd ZERo (fd set *fdset)i Clears all the bits e void FD Set(int fd, fd set *fdset Sets the bit for fd void Fd Clr (int fdfd set faset Clears the bit for fd int FD ISSet (int fd, fd set *fdset)i Checks whether fds bit is set
void FD_ZERO(fd_set *fdset); Clears all the bits void FD_SET(int fd, fd_set *fdset); Sets the bit for fd void FD_CLR(int fd, fd_set *fdset); Clears the bit for fd int FD_ISSET(int fd, fd_set *fdset); Checks whether fd’s bit is set

Robustness? ° Requirements Mass users User Experience o Incidents Server/NetworkClient breakdown? Hacking?
Requirements Mass users User Experience Incidents Server/Network/Client breakdown? Hacking? …

What happened if.? Client(s) Server socket( socket( bind( listen( connect select( FD ISSET(sfd) accept( Hacking! Hacking!!! write( read Server breakdown! read() write( Exceptions here! close() reado check clients() main loop close
Client(s) Server socket() connect() write() read() close() socket() bind() listen() select() write() read() close() read() Hacking! Hacking!!! Exceptions here! Server breakdown! FD_ISSET(sfd) accept() check_clients() main loop …
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 复旦大学:《计算机网络 Computer Networking》课程实验指导_因特网中继聊天(IRC)服务器_socketProgramming-Part1.pptx
- 复旦大学:《计算机网络 Computer Networking》课程实验指导_因特网中继聊天(IRC)服务器_Network Project1 Request 2013.pdf
- 《计算机网络》课程教学资源(参考文献)MACAW_A Media Access Protocol for Wireless LAN’s.pdf
- 《计算机网络》课程教学资源(参考文献)Interdomain Internet Routing.pdf
- 《计算机网络》课程教学资源(参考文献)END-TO-END ARGUMENTS IN SYSTEM DESIGN.pdf
- 《计算机网络》课程教学资源(参考文献)Analysis and Simulation of a Fair Queueing Algorithm.pdf
- 《计算机网络》课程教学资源(参考文献)The Design Philosophy of the DARPA Internet Protocols.pdf
- 《计算机网络》课程教学资源(参考文献)Automated Worm Fingerprinting.pdf
- 《计算机网络》课程教学资源(参考文献)How to 0wn the Internet in Your Spare Time.pdf
- 《计算机网络》课程教学资源(参考文献)A DoS-limiting Network Architecture.pdf
- 《计算机网络》课程教学资源(参考文献)Hash-Based IP Traceback.pdf
- 《计算机网络》课程教学资源(参考文献)Internet Indirection Infrastructure.pdf
- 《计算机网络》课程教学资源(参考文献)Middleboxes No Longer Considered Harmful.pdf
- 《计算机网络》课程教学资源(参考文献)Democratizing content publication with Coral.pdf
- 《计算机网络》课程教学资源(参考文献)Development of the Domain Name System(DNS).pdf
- 《计算机网络》课程教学资源(参考文献)A Scalable Peer-to-peer Lookup Service for Internet Applications.pdf
- 《计算机网络》课程教学资源(参考文献)LOOKING UP DATA in P2P Systems.pdf
- 《计算机网络》课程教学资源(参考文献)Making Gnutella-like P2P Systems Scalable.pdf
- 《计算机网络》课程教学资源(参考文献)Resilient Overlay Networks.pdf
- 《计算机网络》课程教学资源(参考文献)An End-to-End Approach to Host Mobility.pdf
- 复旦大学:《计算机网络 Computer Networking》课程实验指导_因特网中继聊天(IRC)路由_project 2 IRC routing.pptx
- 复旦大学:《计算机网络 Computer Networking》课程实验指导_拥塞控制_project3_2013.pdf
- 复旦大学:《计算机网络 Computer Networking》课程实验指导_拥塞控制_project3-congestion_control.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)01 Introduction.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)02 Protocol Stacks and Layering.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)03 Design Philosophy & Applications.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)04 Socket Programming.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)05 physical_Transmission.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)06 Physical Layer(Cont)& Data Link Layer.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)07 Ethernet.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)08 Software School.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)09 IP Packets.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)10 Intra-Domain Routing.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)11 Multicast.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)12 Inter-Domain Routing BGP(Border Gateway Protocol).ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)13 DNS.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)14 ip-grab-bag(IP Wrap up).ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)15 Virtual Circuits, ATM, MPLS.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)16 Transport Protocols.ppt
- 复旦大学:《计算机网络 Computer Networking》课程电子教案(PPT课件讲稿)17 TCP & Congestion Control.ppt