<file_sep># import asyncio
# import websockets
# async def hello():
# 	async with websockets.connect('ws://localhost:8080') as websocket:
# 		name = input("What's your name??")
# 		await websocket.send(name)
# 		print(websocket)
# 		print("> {}".format(name))
# 		greeting = await websocket.recv()
# 		print("> {}".format(greeting))

# asyncio.get_event_loop().run_until_complete(hello())


from websocket import create_connection
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(module)s -  %(asctime)s - %(levelname)s - %(message)s'))
logger.addHandler(handler)

ws = create_connection("ws://127.0.0.1:12345")
logger.info("Open")
send = "11 23"
logger.info("Sending '{}'...".format(send))
ws.send(send)
logger.info("sent")
logger.info("Receiving...")
result = ws.recv()
logger.info("Received '{}".format(result))
ws.close()
logger.info("Close")


# import websocket
# import thread
# import time
# import logging

# logger = logging.getLogger(__name__)
<file_sep># import asyncio
# import websockets

# async def hello(websocket, path):
# 	name = await websocket.recv()
# 	print("< {}".format(name))

# 	greeting  = "Hello {}!!".format(name)
# 	await websocket.send(greeting)
# 	print("> {}".format(greeting))

# start_server = websockets.serve(hello, 'localhost', 8080)
# asyncio.get_event_loop().run_until_complete(start_server)
# asyncio.get_event_loop().run_forever()

import logging
from websocket_server import WebsocketServer

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(module)s -  %(asctime)s - %(levelname)s - %(message)s'))
logger.addHandler(handler)

def new_client(client, server):
	logger.info('New Client {}:{} has joined'.format(client['address'][0], client['address'][1]))

def client_left(client, server):
	logger.info('New Client {}:{} has left'.format(client['address'][0], client['address'][1]))

def message_received(client, server, message):
	logger.info('Message "{}" has been received from {}:{}'.format(message, client['address'][0], client['address'][1]))
	# reply_message = 'Hi!!' + message
	result = message_processing(message)
	server.send_message(client, str(result))
	logger.info('Message "{}" has been received from {}:{}'.format(result, client['address'][0], client['address'][1]))

def message_processing(message):
	content = message.split(' ')
	return int(content[0]) + int(content[1])

if __name__ == '__main__':
	server = WebsocketServer(port=12345, host='127.0.0.1', loglevel=logging.INFO)
	server.set_fn_new_client(new_client)
	server.set_fn_client_left(client_left)
	server.set_fn_message_received(message_received)
	server.run_forever()<file_sep>## Introduction
This is an experimental implementation of WebSocket in Python.  

## Version
Python: 3.6

## Prerequisites
pip install websocket_server, logging

## Usage

```console
$ git clone https://github.com/Rowing0914/WebSocket_python.git
$ cd WebSocket_python
$ python server.py
## Open another terminal or CMD and execute the command below.
$ python client.py
```