Handling messages equally on server and the client, without code duplication #667
-
I was wondering how I would allow both the server and the client to send and receive messages using the same code. Consider a simple chat app where clients connects to a server and the users, including the host, want to exchange text messages. How I implemented this:
Is this the right way to do this? Or is there a way to send and receive messages using the same code on client and server? Should I connect a local client to the server within the same app to achieve this? Sorry if this is a dumb question; it feels like I misunderstood something very basic about lighyear. But I have looked at the docs and examples for a while now and didn't find an answer to this. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi! No your understanding is totally correct, there's no way to use exactly the same code for both client and server currently. The best you can do would be to have a shared function that you reuse in both the client and server code. Usually it's pretty rare that client and server would want exactly the same logic, but yes I could see a world where an interface that is shared between ClientConnectionManager and ServerConnectionManager is provided |
Beta Was this translation helpful? Give feedback.
Hi!
No your understanding is totally correct, there's no way to use exactly the same code for both client and server currently. The best you can do would be to have a shared function that you reuse in both the client and server code.
Usually it's pretty rare that client and server would want exactly the same logic, but yes I could see a world where an interface that is shared between ClientConnectionManager and ServerConnectionManager is provided