0

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. 

  • You are missing a constructor for Listener (new Listener) and for you IEnumerable list. You need a new Listener for each port number. – jdweng Oct 27 '22 at 10:49
  • So there isnt a shortcut? If i put every game to one port, is it poor software? – Kaan Selçuk Karaböce Oct 27 '22 at 12:09
  • You can have only one connection with same three parameters 1) Source IP 2) Destination IP 3) Port number. If you have more than one game from same client than you need more than one port. There is nothing wrong with having every game use the same port. When a connection is made you need software that sends a command to selects the game. – jdweng Oct 27 '22 at 12:46
  • You mean "There is nothing wrong with having every game use the same port" the games that played same time right? – Kaan Selçuk Karaböce Oct 27 '22 at 13:56
  • It is just really the name of a connection. It is on the same ethernet with just a different port number (a name in this case). – jdweng Oct 27 '22 at 15:56

0 Answers0