© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
38 replies
Larios

❔ Are strings the best way for Server-Client UDP communication?

Hi I'm developing a server-client udp communication system using System.Net ( with classes like UdpClient, IPEndPoint etc. )
Right now my endpoints communicate through strings, example with a stupid request:

1) Server creates a string "Are you hungry?" converts it to bytes and sends it to client through UDP
2) Client receives the bytes, converts them to string, compares the string in a switch statement with a set of predefined strings.
3) Case "Are you hungry?" is met, logic runs and client creates a string "No I'm not hungry", converts it to bytes and sends it to Server through UDP
4) Server receives bytes, converts them to string, compares the string in a switch statement with a set of predefined strings
5) Case "No I'm not hungry" is met, logic runs and server sets the Client's "isHungry" variable to "false"

This all works properly ( for now eheh ), but before i keep going and make a huge project using this system, I just wanted to know if I'm doing things correctly.
My opinion currently is that the system is kinda hard to maintain because I'll end up having a huge amount of predefined strings to compare to.

Am i on the right track? Is there a much better way of doing this? My spider senses tell me that the way i'm doing it makes this way more complex than it should be
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Client/Server communication with Named Pipes
C#CC# / help
15mo ago
❔ Best duplex communication protocol
C#CC# / help
3y ago
✅ SignalR client to client communication (chat)
C#CC# / help
2y ago
Godot UDP Client not functioning properly
C#CC# / help
16mo ago