New to Go, questions about TCP Servers

Hey all. I’m new to Go but am fascinated with the language and am eager to learn more but have a few questions regarding a TCP client/server.

  1. In other languages when I’ve had to send a message from the client to the server such as in a game sending a players coordinates to the server. I create a buffer, then add to the buffer in multiple lines of code. The first line holding data which is the identifier (so the server can differentiate what data it is receiving). The second and third line would hold the characters coordinates respectively. The client then sends the packet holding the buffer to the server and the server unpacks the buffer starting with the ID then the X and finally the Y. Which the server then handles. Basically I’m wondering how I can structure a packet so that when It’s received by the server it knows what to do with it.

  2. When a client connects to the server I want to be able to store the connecting clients socket so that the server can send a packet to a specific client. I’m just having trouble figuring out how to record the socket that the client used and I believe I need to make my server concurrent to do so. Just unsure how this can be achieved.

This about sums up my questions, I have code that I could show as an example but it is more or less a recreation of a tutorial I found online.

I really appreciate any help anyone can provide. Thanks in advance,
Fukle

There are many tutorial/sample code in the web. You can check these

HTH

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.