How to spawn 'dummy clients' on the server-side which use the server's interface in Flask/Socketio

alsuhr

I have a Flask/SocketIO application which currently pairs two clients together to play a game together. Right now the clients are interacting with the server through some compiled client-side Javascript, and I am using socketio to define the sockets which the clients call, e.g., movedForward when that client moved forward. The client-side JS similarly defines websockets which the server will emit to, e.g., partnerTurnedRight when the server is passing the partner's movement to the other player.

I would like to create 'dummy' clients on the server side which can interact with a normal, remote client -- basically, a python implementation of the Javascript which is spawned every time a remote client connects. The idea is to have a server-side "player" play the game with a remote, human client.

I'm not sure how to go about implementing something like this. My intuition is that I should create a separate Flask/SocketIO app (somehow), which has sockets on for the messages the server sends (e.g., partnerTurnedRight) and emits messages the server expects (e.g., movedForward). Then, when a remote client connects, spawn a stateful subprocess which has its own unique sid and is able to interact with the server with the exact same interface as the remote client. However, I'm really not sure how to put everything together or how to actually spawn a server-side client like that.

An example project which does something like this, some pseudocode, or a general structure of how to set something like this up would be greatly appreciated!

(Part of the problem is that I don't know what search terms to use, so it's been hard finding examples.)

Andrew Yochum

You can use the python-socketio package server-side using python. Here's an example of the client usage:

import socketio

sio = socketio.Client()

@sio.on('connect')
def on_connect():
    print('connected')
    sio.emit('Hello')

@sio.on('event')
def on_message(data):
    print('Received ', data)

@sio.on('disconnect')
def on_disconnect():
    print('disconnected')

sio.connect('http://localhost:5000')
sio.wait()

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to use Aurelia's router with server-side routing

Aerospike: How to find from any aerospike server which clients are accessing it?

Detect local clients reliably, server side

Which to use, Session, Cookies, Server-side data?

How to use JSON Sanitizer at Server Side?

How to use Angular 2 server side rendering

How to use DataTables server side column ordering?

Use of containers for server side

In R shiny, how to use on the UI side a value computed on the SERVER side?

how use three semaphore for server clients architecture with shared memory

How to use S3 SSE C (Server Side Encryption with Client Provided Keys) on NodeJS

How to use S3 SSE C (Server Side Encryption with Client Provided Keys) with Ruby

OpenVPN: how can I assign specific netmask for clients from server side?

How to avoid API clients during server side rendering and defer them to the client, in Angular Universal?

How do you create a server-side socket that can accept inputs from multiple clients in Java?

Adding route on OpenVPN server side to connect VPN Clients to the internal LAN

can clients see server side source code ? asp.net

Refresh Tokens - Server Side Storage And Revoking For Multiple Clients

How to insert Huge dummy data to Sql server

How to filter query with a dummy column in sql server?

Which part of the following code will run at the server side

delete entities which are not represented on the server side

How to use server side cursors with psycopg2

How to use Object.values() on server side in Node.js

How to use AQuery in android to fetch the data from server side?

When and how do you use server side JavaScript?

How to use Angular UI-Grid with Server Side Paging

How to use timer in Vapor (server-side Swift)?

How to use search on datatables with server-side processing?