1 / 13

U sing TCP sockets in Perl

U sing TCP sockets in Perl. Created by M Bateman, A Ruddle & C Allison As part of the TCP View project. O verview. TCP socket Client/Server Multithread server Thread pooling server Alternate thread pooling server. T CP Provides. Process to process communication

khoi
Download Presentation

U sing TCP sockets in Perl

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. Using TCP sockets in Perl Created by M Bateman, A Ruddle & C Allison As part of the TCP View project

  2. Overview • TCP socket • Client/Server • Multithread server • Thread pooling server • Alternate thread pooling server

  3. TCP Provides • Process to process communication • Use tuple of IP address & port • Reliable • In order • Socket is one end-point of a two way connection link

  4. TCP Socket Operations

  5. TCP in Perl • Implemented in Socket package • Provides abstractions over • Socket and connect operations • Bind, listen & accept • Remember to close the socket at the end

  6. Daytime server use Socket; $port = 13; $proto = getprotobyname (‘tcp’); socket (SERVER, PF_INET, SOCK_STREAM, $proto); setsockopt (Server, SOL_SOCKET, SO_REUSEADDR, pack (“1”, 1)); bind (SEVER, socket_in ($port, INADDR_ANY)) listen (SERVER, SOMAXCONN); for (; $paddr = accept (CLIENT, SERVER); close CLIENT) { print (CLIENT scalar localtime . “\n”); }

  7. Daytime client use Socket; $port = 13; $remote = $ARGV[0]; $iaddr = inet_aton ($remote); $paddr = sockaddr_in ($port, $iaddr); $proto = getprotobyname (‘tcp’); socket (SOCK, PF_INET, SOCK_STREAM, $proto); connect (SOCK, $paddr); while ($line = <SOCK>) { print ($line); } Close (SOCK);

  8. Issues • Can only deal with one request at once • Performance • Have to wait until the guy in front has finished with the server

  9. Multithreading

  10. Issues • Performance • Thread creation at client connection • Creating threads takes time • Possible deadlock • Due to multithreaded

  11. Issues • Possible deadlock • Resource thrashing • Concurrency errors • Thread leakage • Request overload • Performance • Thread creation still has to be performed in the main loop

  12. Pool Alternative Implementation • Create pool as before • Create thread which makes sure the pool has n thread waiting • On connection take thread from the pool • The above thread makes sure there are always threads in the pool waiting to be used

  13. Summary

More Related