File: server.py

package info (click to toggle)
python-websocketd 0.5-1
  • links: PTS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 368 kB
  • sloc: python: 1,309; javascript: 382; sh: 23; makefile: 11
file content (30 lines) | stat: -rwxr-xr-x 872 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/python3

import fhs
import websocketd

fhs.option('port', 'port to listen to', default = '8888')
config = fhs.init(help = 'testing program for websocketd module', version = '0.1', contact = 'Bas Wijnen <wijnen@debian.org>')

class Server:
	def __init__(self, remote):
		self.remote = remote
		self.remote._websocket_closed = self._closed
		self.remote.ping.bg(lambda arg: self.remote._websocket_close(), 'pang')
		self.remote.func('peng', 'pyng', foo = 'pung', bar = 'prng')

	def func(self, *args, **kwargs):
		print('func called with args %s and %s' % (repr(args), repr(kwargs)))
		return 'func return'

	def pong(self, arg):
		print('pong received, arg = %s' % repr(arg))
		return 3

	def _closed(self):
		print('Server disconnected from client')
		websocketd.endloop()

client = websocketd.RPChttpd(config['port'], Server, tls = False)

websocketd.fgloop()