Closed anjchang closed 7 years ago
Nevermind, i just decided to avoid serverEvent and just use the client's messages to let me know if something was happening. It works for progressing with the rest of the making things talk tutorial.
""" a server that listens for clents and prints what they say
also sends the last client anything that's typed on the keyboard
from Making things talk project 8
client ctrl+] mode character for streaming char
"""
add_library( "net" )
port = 8081
myServer = None
clients = []
def setup():
global myServer
myServer = Server(this,port)
println('Starting server on port '+str(port))
def draw():
global myServer
speakingClient = myServer.available()
if (speakingClient != None):
message = trim(speakingClient.readString())
if speakingClient.ip() not in clients:
connectClient(speakingClient)
println(speakingClient.ip() + '\t' + message)
if (message == 'exit'):
closeClient(speakingClient)
def closeClient(thisClient):
global myServer,clients
print thisClient.ip()+' disconnected'
if thisClient.ip() in clients:
clients.remove(thisClient.ip())
myServer.disconnect(thisClient)
def connectClient(thisClient):
println("we have a new client:" + str(thisClient.ip()))
clients.append(thisClient.ip())
def keyReleased():
global myServer
myServer.write(key)
I'm trying to rewrite the simple server code from Making Things Talk into pyprocessing. serverEvent doesn't seem to work, so I can't tell when clients have connected. Am I using serverEvent() wrong, or is this just not handled? Clients seem to just be able to connect just fine.