I'm doing my first game with network implementation using C#.
Here is my pseudocode:
CLIENTStart a Game Client
Instantiate the client_socket
Connect the client_socket with server
Instantiate objects (player, enemy, etc..)
Instantiate a new Thread for send/receive over TCP
Inside this new thread, a infinite loop runs. Inside this loop:
1.1 get the player position as string, convert to byte[] and then send async through client_socket (client_socket.BeginSend) - OK
1.2 initiate a receive async (client_socket.BeginReceive) to print what Server said to client (NOT OK, receive the same count of bytes but all '\0')
Start the new thread
Enter on gameloop and update objects and render sprites...
SERVERInstantiate a list of client Socket
Bind the IPEndPoint to client connect
Start a new thread to listen connections
On the new thread, iterates a Infinite loop
1.1 accept new client
1.2 start a new thread for the new client, dedicated to receive/send data SYNC
On this new thread,
2.1 another infinite loop receiving data and printing on console (OK, prints the player position)
2.2 sending back a response (OK, send a message)
Is this right? There's a real world example of a simple game, receiving and sending data continuously inside a gameloop? I see a lot of chats, but doesn't looks like a real world exampe to be used in game...
A chat waits for a event to send... but if I'm running at 60fps, I should send and receive data every frame? The multithread approach is really necessary? Why I got the response on client side with same number of bytes that server sends, but the message is all filled with \0?
Thanks