Requesting data from server

Hi all,
I’ve recently been experimenting with the networking system and have been wondering what the best way for a client to retrieve specific data from the host-server.

Here is some context:
A host player has a list of cards (Serializable) and the client need to draw cards from this shared deck to their unique hands and can then send the data back to be used by the host.

So far I understand that it is possible to use RPC calls and can effectively use them to pass card data to the server, I can do the same to call request function on the server, however I’m not quite sure how to get the server to pass the data back to the specific client.

I am considering sending some form of ID via the request to draw a Card but I’ve been wondering if there was a simpler solution to this problem.

Okay after working on it throughout the day I realised I was going about it the wrong way.

The way I solved it was by using the NetworkMessage class.

I did this by creating my own derivation of the MessageBase class :

using UnityEngine.Networking;

public class MessageData : MessageBase
    public short id;
    public MessageData() { id = 0; }
    public MessageData(CardData data){id =;}

And the used this class in my client and host code to transfer the data to each other using Handlers.
Here’s the client side:

private void OnMatchJoined(){
//Other code here
 myClient = new NetworkClient();
 myClient.RegisterHandler(ZMsgType.DrawCard, OnReceiveCard);

    public void RequestCard()
        MessageData msg = new MessageData();
        myClient.Send(myMsgType.RequestCard, msg);
    public void SendCardData(CardData cd)
        MessageData msg = new MessageData(cd);
        myClient.Send(myMsgType.UseCard, msg);

    private void OnReceiveCard(NetworkMessage netMsg)
        MessageData msg = netMsg.ReadMessage<MessageData>();
         //Find cardData from prefab and add to hand
        CardData data = deck.deckData.cardList[];

And here’s the Host side:

public void OnMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
//Other code here
            NetworkServer.RegisterHandler(myMsgType.RequestCard, OnRequestCard);
            NetworkServer.RegisterHandler(myMsgType.UseCard, OnSentCardData);

    private void OnRequestCard(NetworkMessage netMsg)
        CardData data = deck.DrawCard();
        MessageData msg = new MessageData(data);
        NetworkServer.SendToClient(netMsg.conn.connectionId, myMsgType.DrawCard, msg);

    private void OnSentCardData(NetworkMessage netMsg)
        //Game Logic here