Rakkarsoft LLC

FAQ
What is the difference between the license versions?
The freeware license is GPL.
The shareware license can only be sold, resold, or distributed electronically.
The commercial license can be distributed normally.
All licenses can support any number of players.

I'm having problems sending strings.
Use the StringCompressor class to send strings.

My data that I write using bitstreams is messed up on the other side.
Make sure if you write one of the ID_* enumerations you cast it to an (unsigned char). Other than that, make sure your read and write calls match.

My data pointed to by a pointer isn't arriving.
This is the same problem as when trying to use a default copy constructor with allocated memory. You can just send pointers if you want, but it will send the pointer variable rather than the data pointed to. You will need to serialize the contents of pointers yourself.

Question about that ReplicaManager. If the level, and level objects and so on are replicated, but the objects rely on the level being loaded first, how do you ensure that the Level is replicated and fully constructed before everything else? What about more complex relationships?
Participants in the system are not added until you call AddParticipant, unless you were to call SetAutoParticipateNewConnections(true).
Objects in the system are not constructed on other systems until you call Construct, unless you were to call SetAutoConstructToNewParticipants(true).

In the case of a map load, you usually wouldn't want systems still in the menu states to be getting updates for game objects. So you would not add them as a participant in that case.

Another way to handle this is when you get the SetReceiveConstructionCB callback, return REPLICA_PROCESS_LATER. In this way you can defer processing the call until such a time as you choose.

I get very high pings.
Use 0 for the sleep timer, and put a Sleep(0) in your main game loop. This will ensure responsive context switches.

I get error LNK2001: unresolved external symbol ___security_cookie
MSVC .net puts this in libs and dlls by default and it is not supported in MSVC 6. You'll have to rebuild the lib using your own compiler.

I hit an assert in AssertReadUnlockOrder.
You have to call DeallocatePacket in the same order that you called Receive.

How do I use object member remote procedure calls?.
Look at the sample ObjectMemberRPC.

How should I deal with firewalls?
Be sure to specify that your end-users need to open the appropriate ports, or use a port that is probably already open (such as the http port). One way to reduce tech support calls in this regard is to have your application try connecting a local client to a local server. If you can't connect after a couple of tries then the user probably has a firewall blocking this. You can message the user in-game that they probably have a firewall that needs to be turned off on whichever port your game uses.

I get linker errors such as: unresolved external symbol "public: static void __cdecl ClientServerFactory::DestroyRakClientInterface(class RakClientInterface *)"
You didn't link the library into your project. You must have the .lib and not the .dll in the project. See Compiler Setup

I get conflicting lib errors such as follows
LIBCMT.lib(dosmap.obj) : error LNK2005: __dosmaperr already defined in LIBCD.lib(dosmap.obj)
LIBCMT.lib(mbctype.obj) : error LNK2005: __getmbcp already defined in LIBCD.lib(mbctype.obj)
LIBCMT.lib(mbctype.obj) : error LNK2005: __setmbcp already defined in LIBCD.lib(mbctype.obj)
LIBCMT.lib(mbctype.obj) : error LNK2005: ___initmbctable already defined in LIBCD.lib(mbctype.obj)
LIBCMT.lib(tolower.obj) : error LNK2005: __tolower already defined in LIBCD.lib(tolower.obj)
LIBCMT.lib(tolower.obj) : error LNK2005: _tolower already defined in LIBCD.lib(tolower.obj)
LIBCMT.lib(isctype.obj) : error LNK2005: __isctype already defined in LIBCD.lib(isctype.obj)
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library

You need to select Multithreaded Debug and Multithreaded libraries in the project options.

I get linker errors with the BitStream class.
You need to include BitStream.h and BitStream.cpp in your project, among other things. The DLL only exposes interfaces for RakPeer, RakServer, and RakClient.

Dropped connections are not detected and/or I can't reconnect after losing the connection.
In debug TIMEOUT_TIME is set to 30 seconds. A keepalive is sent every 5 seconds. So you may have to wait 35 seconds before you can reconnect. You can change TIMEOUT_TIME to whatever you wish.

I want to, or should I call Send and Receive from multiple threads.
Those functions are not currently threadsafe. There is no benefit to calling them from threads, as they are already optimized to run asynchronously with the main network thread.

I want event callbacks on packet arrival.
There are no event callbacks on packet arrival. If you want an event, poll Receive and make your own event if non-zero is returned.

No offline ping or advertise system data with a broadcast to 255.255.255.255. My packet data length is always 1.
This is intentional to prevent denial of server attacks. After you get a response, send another ping or advertise system call directly to that system.

Is AdvertiseSystem reliable?
Yes.

I can't connect to the other system or other systems can't connect to me. What are some possible reasons?
  • The other system isn't running RakNet.
  • The other system didn't start the connection, or tried to start it and it failed (the startup function returned false).
  • The server has a firewall blocking incoming connections.
  • The server has a firewall blocking UDP data on the specified server port or the server port + 1 (for winsock 2.0+).
  • The client has a firewall blocking UDP data on the specified client port or the server port + 1 (for winsock 2.0+).
  • The server already has the maximum number of connected clients.
  • The server has a lot of network traffic and is too busy to respond to your connection request.
  • You used a different value for connectionValidationInteger than the other system.
  • You are connecting to the wrong port on the server.
  • You entered the wrong IP address of the server. This could be by mistyping or confusing the LAN address with the internet address.
  • One or both systems are not using high priority threads and are at the same time using a lot of CPU power for other threads. This could cause the network threads to not respond to the handshaking sequence fast enough.
  • The handshaking packets were lost due to normal packetloss
  • You did connect, but never handled the network messaging packets that indicated you you did either because you aren't handling any messages or because you didn't handle those in particular.
  • The recipient is behind a NAT and didn't use NAT punch-through.
I get linker errors about winsock function redefinitions
i.e. - error C2011: 'WSAData' : 'struct' type redefinition
i.e. - warning C4005: 'SO_DONTLINGER' : macro redefinition


Add this to your preprocessor definitions
_WINSOCKAPI_
In .Net this would be project / configuration properties / C/C++ / Preprocessor / Preprocessor defintions.
You will get this or a similar warning:
warning C4005: '_WINSOCKAPI_' : macro redefinition unknown(0) : see previous definition of '_WINSOCKAPI_'
You can ignore it.

When ever I define __USE_IO_COMPLETION_PORTS I get a huge number of errors.
All of them are of the type:

winsock2.h(2353) : error C2375: 'WSAAsyncSelect' : redefinition; different linkage
winsock.h(824) : see declaration of 'WSAAsyncSelect'

One for each of the functions exported by winsock2.


Windows.h has to be included after the Rak* headers. __USE_IO_COMPLETION_PORTS has to be defined globally, or before the headers.

I can connect but don't get any data from the other system. What are some possible reasons?

You aren't calling Receive.
The other system didn't send any data, or didn't send any to you.
The other system immediately kicked you after you connected, such as due to you being banned or using a wrong password.
The network disconnected you because of cheating or because it couldn't deliver a reliable packet.

Some kind of networked action happens twice, such as when I press the trigger to fire a bullet two bullets come out.

The server is broadcasting to everyone, including the client that just initiated the action. To fix this, pass the playerId parameter of the packet to the playerId field of Server::Send when broadcasting. This will relay the message to all players BUT the sender.

When I send some particular kind of packet, I immediately get flooded with hundreds of copies the same packet.
This is a feedback loop, caused by the following sort of coding:

// Client
void DoMyFunctionA(void)
{
SendPacketToDoFunctionA();
}

// Server
void HandlePacketToDoFunctionA(void)
{
// Broadcast to all connected players
SendToAllPacketToDoFunctionA();
}

// Client
void ReceivePacketToDoFunctionA(void)
{
DoMyFunctionA();
}

To fix this, either don't have the function that does the action also send the packet, or use a parameter specifying whether to send a packet or not and set that parameter to false if the function is called from the network code. See Programming Tips for help on how to handle this.

How do I create a master game browser?
Use the MasterServer and MasterClient classes provided in Sample Applications

Which version of the multithreaded library does RakNet use?
Multithreaded (/MT)

Since RakNet uses threads does my program need to use the multithreaded library?
If you use the DLL then no. The threads are confined to the dll. If you use the static lib or source then yes.

Can I run more than one instance of the client or server on the same system?
Yes, but each instance will have its own thread and require its own memory. You'll need to remember to give different port assigments to each instance as well. There isn't really any reason to do this since you can use RakPeer to handle multiple outgoing connections.

What's the largest packet I can send?
65535 * (the MTU Size - the UDP / IP header). For a cable modem this is about 95 megabytes. Of course you wouldn't be able to send anything else above the MTU until that arrived. You can use RakNet for small files but for major file transfers you might as well TCP, which is designed for that.

How do I send files?
Just send it as a data stream using RELIABLE, subject to the packet size restriction.

If I purchase one license, can I use it in more than one game?
A site license will allow you to do this. A normal license requires one copy of the license per game. Refer to the License Agreement for full details.

Can I use RakNet in non-games?
Yes

My game is too laggy. How can I decrease lag?
- Use bandwidth more efficiently (see the optimization section in Programming Tips )
- Design your game so it doesn't require as much bandwidth (see the optimization section in Programming Tips )
- Use high priority threads
- Get a faster computer. This will make threads more responsive.
- Get a better internet connection.
- Decrease the number of clients allowed.

Does RakNet use TCP at all?
No.

Will RakNet work with my game written in C?
No.

What OSes does RakNet support?
Unix, Linux, Mac, Windows, and some others.
See Also
Index