tcoy
tcoy

Reputation: 189

Network stream and multiple connections

I am programming a Tcp server for an XNA game that me and a friend are creating and I was wondering how you send to a specific client that is connected to the server using NetworkStream. For example, you can get the host's player position and send that to the server that will send that to the other connected client.

Upvotes: 1

Views: 2611

Answers (1)

nunespascal
nunespascal

Reputation: 17724

You will need to read up on a few things:

This should get you started:

  1. TcpListener
  2. TcpClient

Your server will need to have a TcpListener. Create a list of clients if you want to support multiple clients. You will get one TcpClient for every connected client. Read data from the NetworkStream on each of these clients. When you receive data on one of them, send it to the others.

You will need to define some sort of protocol, so you know when the message from the client is complete and you can send it ahead.

Upvotes: 2

Related Questions