File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed 
assignments/week02/athome Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python 
2+ 
3+ import  socket  
4+ 
5+ host  =  ''  # listen on all connections (WiFi, etc)  
6+ port  =  50000  
7+ backlog  =  5  # how many connections can we stack up 
8+ size  =  1024  # number of bytes to receive at once 
9+ 
10+ ## create the socket 
11+ s  =  socket .socket (socket .AF_INET , socket .SOCK_STREAM ) 
12+ # set an option to tell the OS to re-use the socket 
13+ s .setsockopt (socket .SOL_SOCKET , socket .SO_REUSEADDR , 1 )
14+ 
15+ # the bind makes it a server 
16+ s .bind ( (host ,port ) ) 
17+ s .listen (backlog ) 
18+ fin  =  open ('tiny_html.html' , 'r' )
19+ html  =  fin .read ()
20+ fin .close ()
21+ 
22+ while  True : # keep looking for new connections forever 
23+     client , address  =  s .accept () # look for a connection 
24+     data  =  client .recv (size )
25+     if  data : # if the connection was closed there would be no data 
26+         print  "received: %s, sending it back" % data 
27+         client .send (html ) 
28+         client .close ()
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments