Raknet question

Blitz3D Forums/Blitz3D Programming/Raknet question

Farflame(Posted 2006) [#1]
I'm using Raknet in my program and it's coming along very nicely. I've just started doing some multiplayer testing with several clients and have noticed some errors, due to my newbie programming behaviour, so I'd appreciate any help here.

Here's basically what's happening. When a packet comes in from a client and the server just needs to respond to it, it all works fine, because I can just take the client connection from the packet and respond to that connection.......

But sometimes I need my server to send out signals to connected clients based on various events that have happened. In these cases, the server doesn't have access to a packet, so it can't get the connection from a packet. To solve this (I'm sure there's an easier way), when the client first connects, I stored it's connection data in it's type, using the command......

p\Connection=RN_PacketGetPlayerID(packet)

So later on, when I need to send anything to that client without a packet to respond to, I send it with a line such as ......

RN_ServerSend2(Server,BitStreamOut,HIGH_PRIORITY,RELIABLE,0,P\Connection,False)

Unfortunately, this doesn't work. It seems to be sending the messages out to the wrong clients or something because it's all becoming garbled at the client end.

Is this the best way of achieving this? Is the original line for storing the connection correct?

Any help from Raknet users would be much appreciated :)


KuRiX(Posted 2006) [#2]
Hi Farflame. I am the creator of the wrapper. Happy to know there are some users :)

What you are doing is fine. The PLAYER ID is basically a struct storing ip and port. and the funcion getplayerid returns a pointer to such struct. When are you calling getplayerid?. You should do when the server receives ID_NEW_INCOMING_CONNECTION packet.

What version of the wrapper are you using?


Farflame(Posted 2006) [#3]
Hi Kurix. Yep, still using Raknet, brilliant wrapper. I emailed you earlier, have you altered your email address?

I'm using 0.7. I did try a newer version around Xmas but it was unstable so I backtracked to 0.7.

Here's my function. I've removed a few irrelevant bits, but does it look correct?

Function NetworkUpdate()
	packet=RN_ServerReceive(Server) ; Read any packets received by the server.
	While (packet)
		
		; Then get the message information from the packet.
		Message$=RN_PacketGetData(packet)
		MessageID$=Mid$(Message$,1,1) ; Get the header

		; The message type is now stored in 'MessageID$'
		Select Asc(MessageID$)
			;--------------------------------------------------------------------------------------
			Case ID_NEW_INCOMING_CONNECTION
				; A brand new connection just contacted the server. Set up a clean user.
				p.pdata=New pdata
				p\NetID=RN_PacketGetplayerIndex(packet) ; Make a copy of the player index into
				;p\NetID so that future packets can be matched up with the correct player data.
				p\Connection=RN_PacketGetplayerID(packet)


Does that look correct?


Farflame(Posted 2006) [#4]
Also, is the latest version now stable? I'll upgrade if you're confident that it's stable.


KuRiX(Posted 2006) [#5]
Mmm, it should work. I will try it later, and if i can make a sample i will email it to you!


Sir Gak(Posted 2006) [#6]
Umm, what's a wrapper (other than the plastic that comes around packaged goods)?


KuRiX(Posted 2006) [#7]
Definition from WikiPedia:

"The wrapper acts as an interface between its caller and the wrapped code. This may be done for compatibility, e.g. if the wrapped code is in a different programming language or uses different calling conventions, for security, e.g. to prevent the calling program from executing certain functions, to provide a level of emulation, e.g. a DirectX API which hides the functions of the video card driver. The implication is that the wrapped code can only be accessed via the wrapper. "


Farflame(Posted 2006) [#8]
In the case of Raknet, Kurix has 'wrapped' the original C++ code into a Blitz wrapper, so you can now use Raknet in Blitz3D using Blitz-type commands. And a damn good job he's done of it :)