<s> import asyncio <EOL> import json <EOL> from random import randint <EOL> from autobahn . asyncio . websocket import WebSocketClientProtocol , WebSocketClientFactory <EOL> class HelloClientProtocol ( WebSocketClientProtocol ) : <EOL> def onOpen ( self ) : <EOL> request = { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' } <EOL> self . sendMessage ( json . dumps ( request ) . encode ( '<STR_LIT:utf8>' ) ) <EOL> for _ in range ( <NUM_LIT:0> , <NUM_LIT:10> ) : <EOL> user_id = str ( randint ( <NUM_LIT:1> , <NUM_LIT:100> ) ) <EOL> request = { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' + user_id } <EOL> self . sendMessage ( json . dumps ( request ) . encode ( '<STR_LIT:utf8>' ) ) <EOL> digits = [ randint ( <NUM_LIT:1> , <NUM_LIT:10> ) for _ in range ( <NUM_LIT:3> ) ] <EOL> print ( "<STR_LIT>" . format ( digits ) ) <EOL> request = { '<STR_LIT>' : '<STR_LIT:GET>' , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT:args>' : { '<STR_LIT>' : digits } } <EOL> self . sendMessage ( json . dumps ( request ) . encode ( '<STR_LIT:utf8>' ) ) <EOL> def onMessage ( self , payload , isBinary ) : <EOL> print ( "<STR_LIT>" . format ( payload . decode ( '<STR_LIT:utf8>' ) ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> factory = WebSocketClientFactory ( "<STR_LIT>" , debug = False ) <EOL> factory . protocol = HelloClientProtocol <EOL> loop = asyncio . get_event_loop ( ) <EOL> coro = loop . create_connection ( factory , '<STR_LIT:127.0.0.1>' , <NUM_LIT> ) <EOL> loop . run_until_complete ( coro ) <EOL> loop . run_forever ( ) <EOL> loop . close ( ) </s>
