Page 1 of 1
NetWork questions
Posted: Mon Jun 10, 2024 7:19 pm
by minimy
Using createNetworkServer I see that to send messages from the server to the client I use its clientID=EventClient(), to do it the other way around, on the client I have to put the local client ID. (not obvious but work)
All work good with TCP.
The questions are:
To send from client A to client B what do I need to put as an ID?. I did with server ClientID sended from server to the other clients. Is the right way?
As it connects UDP, it is supposed that by putting the IP the packets are sent to all users, but none arrive, should I use a special port so that they are not blocked?
Will be nice have pb examples in next versions.
Thanks for replys and time!
Re: NetWork questions
Posted: Mon Jun 10, 2024 10:16 pm
by jassing
the id's are generated automatically.
Did you see the examples networkClient.pb and networkServer.pb?
Re: NetWork questions
Posted: Wed Jun 12, 2024 8:52 am
by idle
callingbelieve wrote: Wed Jun 12, 2024 8:32 am
minimy wrote: Mon Jun 10, 2024 7:19 pm
Using createNetworkServer I see that to send messages from the server to the client I use its clientID=EventClient(), to do it the other way around, on the client I have to put the local client ID. (not obvious but work)
All work good with TCP.
The questions are:
To send from client A to client B what do I need to put as an ID?. I did with server ClientID sended from server to the other clients. Is the right way?
As it connects UDP, it is supposed that by putting the IP the packets are sent to all users, but none arrive, should I use a special port so that they are not blocked?
Will be nice have pb examples in next versions.
Thanks for replys and time!
scratch geometry dash
Client A sends a message to the server, indicating that the message is intended for Client B. The message includes Client B's ID and the content of the message. Example: server.send(ClientB_ID, message_from_A)
Server Forwards the Message to Client B:
The server receives the message from Client A.
The server then forwards the message to Client B using Client B's ID.
Example: clientB_ID = getClientID("ClientB")
send(clientB_ID, message_from_A)
UDP communication is connectionless and does not inherently guarantee message delivery. To ensure messages are routed correctly:
Use Server as a Relay: Even with UDP, use the server as a relay to manage client connections and IDs.
Port Handling: Ensure all clients are listening on the correct UDP ports and that your network configuration (e.g., firewall rules) allows UDP traffic on these ports.
And that's what you call an AI chatbot!
Re: NetWork questions
Posted: Wed Jun 12, 2024 12:24 pm
by minimy
Hello Jassing, examples are unidirectional no explain send in both directions, but no problem i solved by my self. Thanks anyway.
Hello Idle, thanks. Then in the server side the right way is send to clients a list with all the conections, is right?
On UDP connections, the maximum 'Length' is 2048. On TCP connections, the maximum 'Length' is 65536
Other question is data control, with tcp in every packet is include 20bytes of control, the 20bytes are included in the maximun packet size or the maximun send size is 65536-20? (using udp is only 8bytes 2048-8)
Will be nice a command like getClients() to get a list wit all conections. Ok, i can make with code but will be nice for forever noobs like me, hehe
Thanks to both for help, have a nice day!!
Re: NetWork questions
Posted: Wed Jun 12, 2024 5:00 pm
by Quin
minimy wrote: Mon Jun 10, 2024 7:19 pm
Will be nice have pb examples in next versions.
Fully agreed; PB's networking layer could do with some love, at the very least in the examples. It's supposed to be a beginner-friendly language and yet it's not even discussed how to continuously read from a socket until you get a full packet?

Re: NetWork questions
Posted: Thu Jun 13, 2024 6:50 pm
by mk-soft
There, that would be nice ...
So I wouldn't have to keep repeating that SendNetWorkData doesn't send the data, but transfers the data to the OS send buffer.
And that ReceiveNetworkData does not receive the data, but reads out the OS receive buffer.