PLEASE HELP NETWORKING IS HARD.
i need help with learning networking so I can help one of my friends(codecat1) with their game. I need to know how to transfer information from the client to the server and the server to the client.
i need help with learning networking so I can help one of my friends(codecat1) with their game. I need to know how to transfer information from the client to the server and the server to the client.
SERVER
read messages Still in serverUpdate() you can read new messages received from the clients
for message in server.messages
print("received message:")
print(message.data)
print("from:")
print(message.connection)
end
Another way to do the same is to iterate over the active connections ; this way you will have the messages sorted by connected clients:
for client in server.active_connections
for message in client.messages
print("received message:")
print(message.data)
print("from:")
print(message.connection)
end
end
send messages Here is how to send messages to clients (connections) ; we will send "Hello!" to all currently connected clients:
for client in server.active_connections
client.send( "Hello!" )
end
You can send all kinds of data: a character String, a Number, a List or an Object. Note that Objects and Lists will be serialized and should not include circular references.
CLIENT
read messages Incoming messages from the server should be read from the course of your update() function (or in a subroutine which is called from update()). This is the only way to ensure that you won't miss any messages and you won't read the same message twice.
update = function()
for message in connection.messages
print("message received from the server:")
print(message)
end
end
You will receive the exact same data sent by the server, which may be a Number, a String, an Object or a List.
send messages You can send a message to the server with:
connection.send(data)
data here could be any Number, String, List or Object you want to send to the server. Here again, make sure there can't be circular references in your data.
Btw this is all in docs
thanks