Hi, I want to make TCP chat application just for fun and exercise.

My idea is to write TCP server and TCP client Win forms application, so is it the right way to do it on this way. I would have 2 (or more) clients and if they want to exchange messages they would send a message to the server and the server would pass a message to the other client, the server would contain a list of active clients so when he received a message from the first client it would read data from the message structure it would have three properties From (string – IpAddress and port), To (string – IpAddress and port) and Message (string), and pass message to another client.
You will definitely learn much more going the TCP route, so don’t do it in SignalR right away. If your goal is to play around with TCP, go ahead.
One thing you will be challenged to do is to build message packets, develop a protocol, handshaking. At least, that would be a good next step after your initial send/recieve .
Handling multiple connections, handling disconnections gracefully, and then abstracting it all away so your host app only sees simple Connect, Send, and some Recieve events.
I support this wholeheartedly, SignalR will work to easily. Enjoy the fun of dealing with TCP, and the bragging rights that come after 😉
i make a library thing a while ago for making simple TCP clients and servers. it works on local IPs and also works across the internet (you need to portforward for across the internet i think)

heres the link to the pastebin
hopefully that helps
Thanks 🙂
There’s a really good bit of documentation from Microsoft for an async TCP server. You don’t have to have yours be async but you’ll love yourself in the end for doing so.
You’ll get far with this!
https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-server-socket-example
Please don’t use this example directly — it uses the old APM model of async.
Thank you for this 🙂
Edit: I already started to write my own, so I will use some logic from this documentation 🙂
You might want to consider using SiganlR for this, please try of examples of real time chat apps
SignalR could be a possibility for this. That, or you could look into the TcpListener class: https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcplistener?view=net-5.0
Thank you for SignalR I would try with this after playing with sockets.
I would say do it from scratch if you want experience, SignalR otherwise or (shameless plug) kainet.simplenetwork nugget package
C# devs
null reference exceptions

source