Client unable to send message.

When i send a network message through the LLAPI either the server does not receive the message or the client does not send it, i get the following warning message on the clients console:

The server receives the connection event and the client creates a connection with the server, so i have no idea whats going on I’ve been researching for a while now but i cant find anyone else having this issue.
Here is my code:

—Server—

    int connectionID;
    int maxConnections = 20;
    int reliableChannelID;
    int hostID;
    int socketPort = 8888;
    byte error;

    void Start ()
    {
        NetworkTransport.Init ();
        ConnectionConfig config = new ConnectionConfig ();
        reliableChannelID = config.AddChannel (QosType.Reliable);
        HostTopology topology = new HostTopology (config, maxConnections);
        hostID = NetworkTransport.AddHost (topology, socketPort);
    }

    void Update ()
    {
        int recHostID;
        int recConnectionID;
        int recChannelID;
        byte[] recBuffer = new byte[1024];
        int bufferSize = 1024;
        int dataSize;
        NetworkEventType recNetworkEvent = NetworkTransport.Receive (out recHostID, out recConnectionID, out recChannelID, recBuffer, bufferSize, out dataSize, out error);

        switch (recNetworkEvent) {

        case NetworkEventType.ConnectEvent:
            print ("connectionRecieved");
            break;

        case NetworkEventType.DataEvent:
            string message = Encoding.Unicode.GetString (recBuffer, 0, dataSize);
            print ("Recieved: " + message);
            break;

        case NetworkEventType.DisconnectEvent:
            break;

        case NetworkEventType.Nothing:
            break;

        }

    }

—Client—

int connectionID;
    int maxConnections = 20;
    int reliableChannelID;
    int hostID;
    int socketPort = 8889;
    byte error;

    void Start ()
    {
        NetworkTransport.Init ();
    }

    public void Connect ()
    {
        ConnectionConfig config = new ConnectionConfig ();
        reliableChannelID = config.AddChannel (QosType.Reliable);
        HostTopology topology = new HostTopology (config, maxConnections);
        hostID = NetworkTransport.AddHost (topology, socketPort);

        connectionID = NetworkTransport.Connect (hostID, "127.0.0.1", 8888, 0, out error);
        print ("connected, connectionID: " + connectionID);
    }

    public void Disconnect ()
    {
        NetworkTransport.Disconnect (hostID, connectionID, out error);
    }

    public void sendMsg (string message)
    {
        byte[] buffer = Encoding.Unicode.GetBytes (message);

        NetworkTransport.Send (hostID, connectionID, reliableChannelID, buffer, message.Length * sizeof(char), out error);
    }

I found out what the problem is: the client doesn’t know its connected because it has to have this code as well otherwise it doesn’t know it’s connected.

int recHostID;
        int recConnectionID;
        int recChannelID;
        byte[] recBuffer = new byte[1024];
        int bufferSize = 1024;
        int dataSize;
        NetworkEventType recNetworkEvent = NetworkTransport.Receive (out recHostID, out recConnectionID, out recChannelID, recBuffer, bufferSize, out dataSize, out error);
        switch (recNetworkEvent) {
        case NetworkEventType.ConnectEvent:
            print ("connectionRecieved");
            break;
        case NetworkEventType.DataEvent:
            string message = Encoding.Unicode.GetString (recBuffer, 0, dataSize);
            print ("Recieved: " + message);
            break;
        case NetworkEventType.DisconnectEvent:
            break;
            break;
1 Like

I have a similar problem to above but with the server: i’m unable to send data from the server to the client maybe it’s because in the server it’s not setting a connection ID? How can i send data from server to clients if the server doesn’t have an connection ID.

Connect request is just polite request for connection establishing. You don’t know will this request successful or not.
So,
client:
connectionId = …Connect();
event = Receive(… receivedConnectionId…);
if event == ConnectEvent && connectionId == receivedConnectionId
Only AFTER THAT I CAN SEND DATA.

Server:
event = Receive(… receivedConnectionId…);
if event == ConnectEvent
WE RECEIVE NEW CONNECTION, new connectionid = receivedConnectionId
NOW WE CAN SEND DATA TO receivedConnectionId

was i clean?

So the server uses the clients id to send a message to them?

        NetworkTransport.Send (hostID, targetID, reliableChannelID, buffer, message.Length * sizeof(char), out error);

Where targetID is a clients connection ID.

@Epic-Username , hm, no :slight_smile:
I guess the best approach will be, PM me with your project and I will take a look, ok?