def __init__(self, parent, settings, address="0.0.0.0", port=PORT): super(QtCore.QObject, self).__init__(parent) self.settings = settings self.server = QtWebSockets.QWebSocketServer(parent.serverName(), parent.secureMode(), parent) if self.server.listen(QtNetwork.QHostAddress(address), port): print('Listening: ' + self.server.serverName() + ' : ' + self.server.serverAddress().toString() + ':' + str(self.server.serverPort())) else: print('error') self.server.newConnection.connect(self.on_new_connection) self.clientConnection = None self.gui = None self.msg_responses = None self.msg_uuids = None self.users = {} self.self_name = None self.potions_disable_timer = QTimer() self.potions_disable_timer.timeout.connect(self.clear_effects) print(self.server.isListening())
def __init__(self, songbook="", parent=None): super(KaraokeServer, self).__init__(parent) self.songbook = songbook self.password = "" self.playlist = [] self.maxConnectedClients = 0 # The KaraokeServer consists of a WebSocketServer and a WebServer. self.webSocketServer = QtWebSockets.QWebSocketServer( "Karaoke Server", QtWebSockets.QWebSocketServer.NonSecureMode, self) self.webSocketServerPort = 0 self.WebSocketMethods = { 'getSongbook': self._getSongbook, 'getPlaylist': self._getPlaylist, 'updatePlaylist': self._updatePlaylist, 'addToPlaylist': self._addToPlaylist, 'play': self._play, 'nextSong': self._nextSong, 'stop': self._stop, 'playNow': self._playNow, 'playNext': self._playNext, 'submitPassword': self._submitPassword } self.webServer = WebServer() # Clients hold all clients connected to the WebSocketServer. Clients # are added when they connect and removed when they disconnect. # Admins holds IPs of clients who have administrative privileges. self.clients = {} self.admins = set()
def __init__(self, parent): super(QtCore.QObject, self).__init__(parent) self.clients = [] self.server = QtWebSockets.QWebSocketServer(parent.serverName(), parent.secureMode(), parent) if self.server.listen(QtNetwork.QHostAddress.LocalHost, 1302): print('Connected: ' + self.server.serverName() + ' : ' + self.server.serverAddress().toString() + ':' + str(self.server.serverPort())) else: print('error') self.server.newConnection.connect(self.onNewConnection)
def __init__(self, parent): super(QtCore.QObject, self).__init__(parent) self.clients = [] self.server = QtWebSockets.QWebSocketServer(parent.serverName(), parent.secureMode(), parent) if self.server.listen(QtNetwork.QHostAddress.Any, 0): global WS_PORT WS_PORT = self.server.serverPort() print(self.server.serverName() + ' : ' + self.server.serverAddress().toString() + ':' + str(self.server.serverPort())) else: print('error') self.serverThread = QThread() # self.server.moveToThread(self.serverThread) self.server.newConnection.connect(self.onNewConnection) print(self.server.isListening())
def __init__(self, parent): super(QtCore.QObject, self).__init__(parent) self.timer = QTimer() self.timer.setInterval(50) self.timer.timeout.connect(self.send_data) self.clients = [] print("server name: {}".format(parent.serverName())) self.server = QtWebSockets.QWebSocketServer(parent.serverName(), parent.secureMode(), parent) if self.server.listen(QtNetwork.QHostAddress('127.0.0.1'), 8080): print('Listening: {}:{}:{}'.format( self.server.serverName(), self.server.serverAddress().toString(), str(self.server.serverPort()))) else: print('error') self.server.acceptError.connect(self.onAcceptError) self.server.newConnection.connect(self.onNewConnection) self.clientConnection = None print(self.server.isListening())
data = [ { 'pos': (int(u['position']['x']), int(u['position']['z'])), 'data': u['name'], 'brush': mkBrush( 'g' ), #mkBrush("r" if u['name'] == self.server.self_name else "g"), 'symbol': ("s" if u['name'] == self.server.self_name else "o"), } for u in users.values() ] self.map_item.setData(data) #map(lambda x: "Red" if x['name'] == self.server.self_name else "Green", users.values()) # self.map_item.setData(x=[int(u['position']['x']) for u in users.values()], # y=[int(u['position']['z']) for u in users.values()], # data=[u['name'] for u in users.values()]) if __name__ == '__main__': import sys QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication(sys.argv) settings = QSettings("PositiveState", "MC Classroom") serverObject = QtWebSockets.QWebSocketServer( 'My Socket', QtWebSockets.QWebSocketServer.NonSecureMode) server = WSServer(serverObject, settings, address='0.0.0.0') gui = MCClassroom(settings, server) server.gui = gui serverObject.closed.connect(app.quit) app.exec_()
def buildSocket(app): serverObject = QtWebSockets.QWebSocketServer( 'My Socket', QtWebSockets.QWebSocketServer.NonSecureMode) server = MyServer(serverObject) serverObject.closed.connect(app.quit) return (server, serverObject)
from websocketclientwrapper import WebSocketClientWrapper if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) jsFileInfo = QtCore.QFileInfo( os.path.join(QtCore.QDir.currentPath(), "qwebchannel.js")) if not jsFileInfo.exists(): QtCore.QFile.copy(":/qtwebchannel/qwebchannel.js", jsFileInfo.absoluteFilePath()) server = QtWebSockets.QWebSocketServer( "QWebChannel Standalone Example Server", QtWebSockets.QWebSocketServer.NonSecureMode, ) if not server.listen(QtNetwork.QHostAddress.LocalHost, 12345): print("Failed to open web socket server.") sys.exit(-1) clientWrapper = WebSocketClientWrapper(server) channel = QtWebChannel.QWebChannel() clientWrapper.clientConnected.connect(channel.connectTo) dialog = Dialog() core = Core(dialog) channel.registerObject("core", core) file = os.path.join(os.path.dirname(os.path.realpath(__file__)),