<s> import socket <EOL> import ssl <EOL> import spdy . frames <EOL> import spdy <EOL> from pprint import pprint <EOL> server = socket . socket ( ) <EOL> server . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , <NUM_LIT:1> ) <EOL> server . bind ( ( '<STR_LIT>' , <NUM_LIT> ) ) <EOL> server . listen ( <NUM_LIT:5> ) <EOL> ctx = ssl . SSLContext ( ssl . PROTOCOL_SSLv23 ) <EOL> ctx . load_cert_chain ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ctx . set_npn_protocols ( [ '<STR_LIT>' ] ) <EOL> def handle_frame ( conn , f ) : <EOL> print ( "<STR_LIT>" , f ) <EOL> if isinstance ( f , spdy . frames . Ping ) : <EOL> ping = spdy . frames . Ping ( f . uniq_id ) <EOL> conn . put_frame ( ping ) <EOL> print ( str ( ping ) + "<STR_LIT>" ) <EOL> elif isinstance ( f , spdy . frames . SynStream ) : <EOL> resp = spdy . frames . SynReply ( f . stream_id , { '<STR_LIT:status>' : '<STR_LIT>' , '<STR_LIT:version>' : '<STR_LIT>' } , flags = <NUM_LIT:0> ) <EOL> conn . put_frame ( resp ) <EOL> print ( str ( resp ) + "<STR_LIT>" ) <EOL> data = spdy . frames . DataFrame ( f . stream_id , b"<STR_LIT>" , flags = <NUM_LIT:1> ) <EOL> conn . put_frame ( data ) <EOL> print ( str ( data ) + "<STR_LIT>" ) <EOL> try : <EOL> while True : <EOL> try : <EOL> sock , sockaddr = server . accept ( ) <EOL> ss = ctx . wrap_socket ( sock , server_side = True ) <EOL> conn = spdy . Context ( spdy . SERVER ) <EOL> while True : <EOL> d = ss . recv ( <NUM_LIT> ) <EOL> conn . incoming ( d ) <EOL> while True : <EOL> f = conn . get_frame ( ) <EOL> if not f : <EOL> break <EOL> handle_frame ( conn , f ) <EOL> outgoing = conn . outgoing ( ) <EOL> if outgoing : <EOL> ss . sendall ( outgoing ) <EOL> except Exception as exc : <EOL> print ( exc ) <EOL> if not "<STR_LIT>" in str ( exc ) : raise <EOL> continue <EOL> finally : <EOL> server . close ( ) </s>
