Multiplayer Unity Game Darkrift2 multiple ports

78 Views Asked by At

i am building multiplayer game with unity and darkrift2(framework), the game works, now just one game(match) can be played at server, i want to make it more than one. There are ports, I should enter the right port to connect. In darkrift2 documentation there were a page that shows how to access multiple ports(I want like a lot of port, 1000-10000) with its code. But I couldn't apply that code to my project. It gives errors. I don't know is it absolete? If you understand this links comments can you tell me?:

https://www.darkriftnetworking.com/DarkRift2/Docs/2.9.0/advanced/network_listeners.html

public class BugWarsOnline : NetworkListener
{

    public override Version Version => new Version(1, 0, 0);

    public BugWarsOnline(NetworkListenerLoadData pluginLoadData) : base(pluginLoadData)
    {

    }

    public override void StartListening()
    {
        //When a new client connects we need to call RegisterConnection(NetworkServerConnection connection)
        //RegisterConnection(new NetworkServerConnection());
    }



}



using DarkRift;
using DarkRift.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Bug_Wars_Online
{
public class BWNetworkServerConnection : NetworkServerConnection
{//Whether we're connected
    public ConnectionState ConnectionState { get; }

    //A list of endpoints we're connected to on the client
    public IEnumerable<IPEndPoint> RemoteEndPoints { get; }

    //Given a named endpoint this should return that
    //public IPEndPoint GetRemoteEndPoint(string name)
    //{
    //    if (name == "tcp")
    //        return tcpEndPoint;
    //    else
    //        throw new ArgumentException("Not a valid endpoint name!");

    //}

    //Called once for initialization
    public void StartListening()
    {
        throw new NotImplementedException();
    }

    //Sends a message reliably...
    public bool SendMessageReliable(MessageBuffer message)
    {
        HandleMessageReceived(message, SendMode.Reliable);
        throw new NotImplementedException();
    }

    //...Sends a message unreliably!
    public bool SendMessageUnreliable(MessageBuffer message)
    {

        HandleMessageReceived(message, SendMode.Unreliable);
        throw new NotImplementedException();
    }

    //Called when the server wants to disconnect the client
    public bool Disconnect()
    {
        HandleDisconnection();
        throw new NotImplementedException();
    }

    //We should call HandleMessageReceived(MessageBuffer message, SendMode sendMode) when we get a new message from the client
    //And HandleDisconnection(...) if the client disconnects
}
}

Error Code:CS0534

Another option, I want to make every port listenable, I should write every port's number to server.config.xml to make all ports listenable. Do you know a shortcut to how to make all ports listenable from server.config.xml

<listeners>
<listener name="DefaultNetworkListener" type="BichannelListener" address="0.0.0.0" port="1560">
  <settings noDelay="true" />
</listener> 
  

And If I can not do that, I won't use ports, I have to send every message with one more value (game no), and it will be more costly and I don't want this. If I put all the games(matches) to 1 port and give every game(match) to game no, is it high costly? Is it like normal thing to put everything to one port? If its possible I want to make the game more efficient. 

0

There are 0 best solutions below