- Home /
Network Send Server Data to Client and Vice Versa
//On my server, I used InitializeServer to Start the Server
Network.InitializeServer (10, 1234, useNat);
//On my client side to connect to the Server.
Network.Connect("127.0.0.1", 1234);
Now, I want to send data to each other. For example, Server will send data to all clients, the count of clients connected. The client will accept that message and put the result in the UI Text.
I already read about NetworkMessage but It's only work if I used NetworkServer,Listen / NetworkClient.RegisterHandler. and also about [SyncVar] and [ClientRPC] but still I can't find my answer,
I'm hoping that somebody will help me about this. I just started learning about Unity Networking.
Source Code with a proper explanation will help, Unity Documentation made my head blow off.
Thanks in advance.
Answer by toddisarockstar · Apr 01, 2017 at 01:36 AM
initialize.server is for creating a server and simply listening to a port. but unless you have setup a router to forward a port and set a PC to a static IP address, you have no way of the machines talking to each other without a master server first to get each others actuall addresses!
I think unity might still have a free test server. or i hear photon works well to set all that stuff up for you.
start googling "master server for unity".
how about implementing game server hosted server online, then player to connect to that server what function is the best for this, the said photon can handle with this? thnx
photon is very popular here. it's server space that is setup just for unity. it's pry just what you need. after you install the photon package, they have their own functions / commands you call in your scripts. so you would say things like: PhotonNetwork.Connect(blah,blah); they would also give you commands to get listings of other users waiting to join a game and things like that.
last i heard. photon is free to setup. If your game is successful, I would guess the free version has some limit on how much traffic or how many users can connect before you gave them a fee.
Your answer
![](https://koobas.hobune.stream/wayback/20220612114124im_/https://answers.unity.com/themes/thub/images/avi.jpg)