Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

PY | websocket - server

#!/usr/bin/env python

import asyncio
import websockets

async def echo(websocket, path):
    async for message in websocket:
        await websocket.send(message)

asyncio.get_event_loop().run_until_complete(
    websockets.serve(echo, 'localhost', 8765))
asyncio.get_event_loop().run_forever()
Comment

PY | websocket - client

#!/usr/bin/env python

import asyncio
import websockets

async def hello(uri):
    async with websockets.connect(uri) as websocket:
        await websocket.send("Hello world!")
        await websocket.recv()

asyncio.get_event_loop().run_until_complete(
    hello('ws://localhost:8765'))
Comment

PY | websocket - server

#!/usr/bin/env python

import asyncio
import websockets

async def echo(websocket, path):
    async for message in websocket:
        await websocket.send(message)

asyncio.get_event_loop().run_until_complete(
    websockets.serve(echo, 'localhost', 8765))
asyncio.get_event_loop().run_forever()
Comment

PY | websocket - client

#!/usr/bin/env python

import asyncio
import websockets

async def hello(uri):
    async with websockets.connect(uri) as websocket:
        await websocket.send("Hello world!")
        await websocket.recv()

asyncio.get_event_loop().run_until_complete(
    hello('ws://localhost:8765'))
Comment

PREVIOUS NEXT
Code Example
Python :: python singleton 
Python :: get ticks pygame 
Python :: how to split string by list of indexes python 
Python :: split path in list of directories 
Python :: appending objects to a list contained in a dictionary python 
Python :: keras normalize 
Python :: hex to string python 
Python :: check runtime python 
Python :: heroku[web.1]: Process exited with status 3 
Python :: python requests post form data 
Python :: for each loop python 
Python :: python sort a 2d array by custom function 
Python :: get number in string python 
Python :: array concatenation in python 
Python :: scaling pkl file? 
Python :: calculate mean of column pandas 
Python :: input code for python 
Python :: get value from index python 
Python :: pronic number program in python 
Python :: python loop list 
Python :: pandas dataframe any along row 
Python :: xarray get number of lat lon 
Python :: re python3 
Python :: can serializer returns an object in django 
Python :: oops concept in python 
Python :: map a list to another list python 
Python :: how to use django-rest-framework-datatables 
Python :: yml anaconda 
Python :: how to declare private attribute in python 
Python :: post list python 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =