diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..d5e2bb1 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python server.py \ No newline at end of file diff --git a/README.md b/README.md index c2a2c97..18397fd 100644 --- a/README.md +++ b/README.md @@ -1,110 +1,10 @@ -Websocket Server -======================= +#Web Chess +This application uses a python web socket to play a game of chess. There can be multiple clients connected and each has access to the game board to move any piece. This allows for flexibility in how you play. Messages are broadcast to all clients in the chat area to the left. Clicking on a game piece will select it and using the arrow keys will move the piece. When the selected piece collides with a piece of the opposite color, that piece is removed from play 'captured'. -A minimal Websockets Server in Python with no external dependencies. +Notes: I am currently unable to deploy this application to heroku or Python Anywhere so it just runs locally for now. - * Works with Python2 and Python3 - * Clean simple API - * Multiple clients - * No dependencies +#How to run: +In a command prompt, navigate to the folder containing server.py and run the server using 'python server.py'. A message should appear stating that the server is running. You can then open up as many client.html windows as you want. Any message or piece movement will be sent to all connected clients. To stop the server, in the command prompt, press control+c and type 'exit'. -Notice that this implementation does not support the more advanced features -like SSL etc. The project is focused mainly on making it easy to run a -websocket server for prototyping, testing or for making a GUI for your application. - -If this project reduced your development time feel free to buy me a coffee. - -[](https://www.paypal.me/seferidis) - - -Usage -======================= -You can get a feel of how to use the websocket server by running - - python server.py - -Then just open `client.html` in your browser and you should be able to send and receive messages. - - -Using in your project -======================= - -You can use the project in three ways. - - 1. Copy/paste the *websocket_server.py* file in your project and use it directly - 2. `pip install git+https://github.com/Pithikos/python-websocket-server` (latest code) - 3. `pip install websocket-server` (might not be up-to-date) - -For coding details have a look at the [*server.py*](https://github.com/Pithikos/python-websocket-server/blob/master/server.py) example and the [API](https://github.com/Pithikos/python-websocket-server#api). - - -API -======================= - -The API is simply methods and properties of the `WebsocketServer` class. - -## WebsocketServer - -The WebsocketServer can be initialized with the below parameters. - -*`port`* - The port clients will need to connect to. - -*`host`* - By default the `127.0.0.1` is used which allows connections only from the current machine. If you wish to allow all network machines to connect, you need to pass `0.0.0.0` as hostname. - -*`loglevel`* - logging level to print. By default WARNING is used. You can use `logging.DEBUG` or `logging.INFO` for more verbose output. - - -### Properties - -| Property | Description | -|----------|----------------------| -| clients | A list of `client` | - - -### Methods - -| Method | Description | Takes | Gives | -|-----------------------------|---------------------------------------------------------------------------------------|-----------------|-------| -| `set_fn_new_client()` | Sets a callback function that will be called for every new `client` connecting to us | function | None | -| `set_fn_client_left()` | Sets a callback function that will be called for every `client` disconnecting from us | function | None | -| `set_fn_message_received()` | Sets a callback function that will be called when a `client` sends a message | function | None | -| `send_message()` | Sends a `message` to a specific `client`. The message is a simple string. | client, message | None | -| `send_message_to_all()` | Sends a `message` to **all** connected clients. The message is a simple string. | message | None | - - -### Callback functions - -| Set by | Description | Parameters | -|-----------------------------|---------------------------------------------------|-------------------------| -| `set_fn_new_client()` | Called for every new `client` connecting to us | client, server | -| `set_fn_client_left()` | Called for every `client` disconnecting from us | client, server | -| `set_fn_message_received()` | Called when a `client` sends a `message` | client, server, message | - - -The client passed to the callback is the client that left, sent the message, etc. The server might not have any use to use. However it is passed in case you want to send messages to clients. - - -Example: -```` -import logging -from websocket_server import WebsocketServer - -def new_client(client, server): - server.send_message_to_all("Hey all, a new client has joined us") - -server = WebsocketServer(13254, host='127.0.0.1', loglevel=logging.INFO) -server.set_fn_new_client(new_client) -server.run_forever() -```` - -## Client - -Client is just a dictionary passed along methods. - -```` -{ - 'id' : client_id, - 'handler' : client_handler, - 'address' : (addr, port) -} -```` +#Known Issues +Selected piece on other clients do not capture pieces like what happens on the client that is controlling the selected piece. \ No newline at end of file diff --git a/client.html b/client.html index 598a6a6..38def0f 100644 --- a/client.html +++ b/client.html @@ -1,24 +1,62 @@
-| + + + + | + ++ + | +