Some questions about DefNet and Networking

Hi, so I’m an absolute beginner in networking and DefNet, so I think it’s a good idea to had a topic about networking not only for me but for anyone in the future who has questions about this topic.

Anyway, right now after some testing, I finally made hosting and joining using the P2P Discovery for IP address and TCP server and client. But for some reasons, after connecting, I still cannot send message between server and client, and I have no idea why, and it didn’t throw any errors.

Can you give it a look? Sorry for my bad codes :sweat: I was just trying to make it works :sweat:

Are you getting any errors? Are both the client and server on the same local network? Or maybe on the same machine?

Yes, both client and server are on the same server network, and I have tested with both with the same machine and different machine under the same network.

I didn’t receive any errors, and I’ve tried to run your examples also, and it still run like normal. I think the biggest different is that I’ve put every object in the same collection (from the server, the client, the GUI and the p2p discovery), and I saw yours are put in different collection, and by loading the collection, it can be only server/client. Is it possible that running them in the same collection can cause conflict? I think I will rewrite and restructure the system, if it’s still not working, I might need your help again :sweat:

No that should not be a problem.

1 Like

Hi, I have rewritten all the structure and the code all over again, and as I expected, it still didn’t show the data send and data receive. But in the end, I make it works again, and the solution makes me confuse and laugh at the same time.

Eventually, all I need to do is to add \n in the end of the string. I’ve changed:

self.client.send("data")

to

self.client.send("data\n")

I think this should be noted down in the docs again, as I think it might cause some confusion to some (like me). And because of this, it brings me to the next question:
What if I want to send a table, or other variables’ types, will DefNet support? And if it can, does it need some special requirements (likes with \n in the end of string)?

1 Like

The TCP server is configured to read “lines of data”, see the pattern configured here:

The “*l” means read until end of line.

Sure, you need to decide how to encode the Lua table. The server and client were created as examples and you may need to modify them to suit your needs. For a high performance data intense usecase I’d probably use a binary data format such as protobuf and read chunks of bytes instead of lines of text.

2 Likes