UDP FPS

Blitz3D Forums/Blitz3D Beginners Area/UDP FPS

Steven Noyce(Posted 2006) [#1]
Ok, I want to make a multiplayer first person shooter using UDP. I think my main problem is having players join the game. I know this code is pathetic and does not work, but how could I make it work?
Print "1=client"
Print "2=host"
game=Input(">")
name=Input("Name:")
sendudpstream=CreateUDPStream()
resvudpstream=CreateUDPStream()

Print "press a key when all desired players have joined"

Type multiplayer
	Field id
	Field mesh
End Type

Repeat
	msg$=RecvUDPMsg(resvudpstream)
	udpmsgtype=Right(msg,3)
	If udpmsgtype="100"
		m.multiplayer=New multiplayer
		m\id=UDPMsgIP(resvudpstream)
		m\mesh=CreateCube()
		Print "A New Player has Joined!!!"
	EndIf
	For m.multiplayer=Each multiplayer
		WriteLine sendudpstream,"100"
		SendUDPMsg(sendudpstream,m\id)
	Next
Until GetKey()



Wings(Posted 2006) [#2]
well to start you must decide a packet standard.. or else the udp thing wont work as you plan then adding more that 2 players.

1) Write a good network plan.. games is working best then its packet that is send and not messages !

;RFC game cordinate packet.
0-3 int Type of packet..( 2=cordinate )
4-7 int Id of player (1-999999)
8-11 int xpos of player.
12-15 int ypos of player
16-19 int zpos of player.
20-23 int direction (y rotation)


Steven Noyce(Posted 2006) [#3]
What???
Not sure I understood that.


jfk EO-11110(Posted 2006) [#4]
EDITED: never mind (thought you cannot compare an int to a string, but I see you actually can, tho it's not that proper)

I think you're on the right track. Add the client connection code.

Then as suggested, design packet standards like in the example. So a packet will contain a lot of information that is sent frequently. Since UDP has no error correction I'd suggest to append the 32 bit checksum at the end of each packet, so you can determine the integrity of tha data. If there's data loss, you can reorder a package. Simple example of a packet

unique_packet_ID
player_ID
packet_lenght
x
y
z
pitch
yaw
roll
checksum

For the checksum all you have to do is:

Add all values together and AND it wil a given value, eg with 24 Bit:

chck=0
chck=(chck+player_ID) and $FFFFFF
chck=(chck+packet_lenght) and $FFFFFF
chck=(chck+x) and $FFFFFF
chck=(chck+y) and $FFFFFF
chck=(chck+z) and $FFFFFF
chck=(chck+pitch) and $FFFFFF
chck=(chck+yaw) and $FFFFFF
chck=(chck+roll) and $FFFFFF

Now when the receiver has decoded the packet, it may reconstruct the checksum and compare it if it fits the received checksum. If they differ then data damage is likely, then it may reorder the packet identified by the unique packet ID.


Steven Noyce(Posted 2006) [#5]
How do I get the integer IP address of the machine the program is running on?


jfk EO-11110(Posted 2006) [#6]
the machine may have several ips, you need to choose one of them:

For i=0 To CountHostIPs("")
Print DottedIP( HostIP(i) )
Next
WaitKey()

needless to say, behind a router you will get the lan ip that is diffrent from the ip you have when you access a webpage. A simple workaround would be to call a php script on a webserver that will return the clients ip.


Steven Noyce(Posted 2006) [#7]
So, when I choose one, is there a way to tell wich one I should choose? Is one better than another? Do they do different things?


jfk EO-11110(Posted 2006) [#8]
Some of them are not valid IPs for connections. Here I got 0.0.0.17 and 3.0.0.2 - such IPs cannot be used of course. So you need to search for the one that "sounds" good. Tho I think maybe there is a better way, make sure to check the code archives. This code for example:
http://www.blitzbasic.com/codearcs/codearcs.php?code=139
assumes HostIP(1) is the right one, but I'm not sure if this is really bulletproof.


Steven Noyce(Posted 2006) [#9]
Why does this not work?
http://www.freewebs.com/blitznerd/FPS/UDP FPS.zip


Regular K(Posted 2006) [#10]
Try reuploading it with an underscore instead of a space inbetween UDP and FPS


Steven Noyce(Posted 2006) [#11]
Just copy and paste the full url into your browser url bar and it works!


jfk EO-11110(Posted 2006) [#12]
to be honest, "Why does this not work?" requests scare me.


Steven Noyce(Posted 2006) [#13]
Sorry, but I am realy not sure why it doen't work. It seems like it should to me.


Steven Noyce(Posted 2006) [#14]
This intro code is REALY starting to get on my nerves.
All I need to do is have each computer get all of the others IP addresses. It seems so simple. It also seems like this code should acomplish this very thing.

When I run this code on two computers, they both print out their own (perfectly acceptable) IP adresses, and then, when the other computer joins, they print "1" instead of the other computers IP adress like they are supposed to.

Can any one see what is wrong with this code? Please help me out with this!
Print "1=client"
Print "2=host"
game=Input(">")
name=Input("Name:")
sendudpstream=CreateUDPStream()
resvudpstream=CreateUDPStream()
StartNetGame()
directplayip=CreateNetPlayer(name)

Print "press any key when all desired players have joined"

Type multiplayer
	Field id$
	Field mesh
End Type

CountHostIPs("")
findip$=Str(HostIP(1))
ip$=LSet(findip,11)
Print ip

Repeat
	createnew=True
	msg$=RecvNetMsg()
	If NetMsgType()=100
		For m.multiplayer=Each multiplayer
			If Left(msg,11)=m\id Then createnew=False
		Next
		If createnew=True
			m.multiplayer=New multiplayer
			m\id=Left(msg,11)
			m\mesh=CreateCube()
			Print m\id
		EndIf
	EndIf
	SendNetMsg(100,ip,directplayip,0)
Until GetKey()



Regular K(Posted 2006) [#15]
All the commands that have Net in it are DirectPlay.
But your also trying to do a UDP stream.

DirectPlay is a lot easier than doing it your own way, but its also slower.

http://blitzbasic.com/codearcs/codearcs.php?cat=4&order=&asc=&lang_id=1

Look at those, they should help if not confuse you even more.

And read the command list more ;)


Dreamora(Posted 2006) [#16]
what are you doing there?
Either you use UDP or you don't use it, but mixing it with DPlay is a quite suicidical step you should not do.
With UDP you have to program your own player handling etc (o look for gnet and other network libs for Blitz), you cant use the directplay or tcp commands

http://www.blitzbase.de/befehle2d/createudpstream.htm


Steven Noyce(Posted 2006) [#17]
I am not trying to use both in the game or at the same time. I am trying to use DirectPlay in the starting screen to get the IP addresses of all of the players so that I can then use UDP during the actual game. I know this is probably not the best way to do it, but how else can I get all of the IP addresses of all of the players who join?

A better or easier way to do this would help me a lot!


jfk EO-11110(Posted 2006) [#18]
No offence. I tell you what's wrong with your code. you didn't read the manual. Be prepared to get less and less help around here if you don't make your homework.

Additionally, a "thanks" from time to time when people are trying to help (instead of no reaction) will be useful as well.

If you position the cursor on the command "RecvNetMsg()" in your program and hit the F1 key twice you will be ported to the command reference, explaining this command with an example. There you'll see you are using RecvNetMsg()the wrong way. It will not return any data, but only true or false, depending on if there is a new message to read. The message data must then be read by the command "NetMsgData$()".

So your mainloop would look like this:
Repeat
 createnew=True
 If RecvNetMsg()
  If NetMsgType()=100
   msg$=NetMsgData$()
   For m.multiplayer=Each multiplayer
    If Left(msg,11)=m\id Then createnew=False
   Next
   If createnew=True
    m.multiplayer=New multiplayer
    m\id=Left(msg,11)
    m\mesh=CreateCube()
    Print m\id
   EndIf
  EndIf
 EndIf
 SendNetMsg(100,ip,directplayip,0)
Until GetKey()

Tho, sending this message again and again in the last line seems kind of useless to me, if not an overkill for the network.

Don't get me wrong, I'm only trying to help you to help yourself.


Steven Noyce(Posted 2006) [#19]
Thank you SOOOOOOOOOOOOO MUCH for pointing that out to me!

I have used DirectPlay in the past succesfully so I was a little overconfident this time and just typed in the code, only looking at the command refrence for a few different comands that I was not sure I remembered corectly, but I totaly forgot the basics of DirectPlay! I am very sorry for not looking at my code more carefully, but I just could not see anything wrong with it. I feel realy stupid now that you pointed that out.

Sorry for not saying thank you more often, I guess I was just too frustrated to think about how I was affecting other people.


Steven Noyce(Posted 2006) [#20]
I have decided I am probably starting out WAY over my head. So, I decided to downgrade to a simple 2d program and see if I could get it to work. I am just finding the ip address of my 2 computers before hand and typing it directly into the code.

Sorry that I keep asking for so much help, but I feel like I am drowning in all this complicated code and advanced resources. I feel like there is no simple way to do this. Maybe there isn't. But I REALY want to be able to code and understand UDP. I feel like this is about the dumbest question I could ask, but why does this code not work?
Graphics 640,480
SetBuffer BackBuffer()
UDPTimeouts 100
sendudpstream=CreateUDPStream()
recvudpstream=CreateUDPStream()

x1=50
y1=50
x2=100
y2=100

While Not KeyDown(1)
Cls
If KeyDown(200) Then y1=y1-2
If KeyDown(208) Then y1=y1+2
If KeyDown(203) Then x1=x1-2
If KeyDown(205) Then x1=x1+2
Color 0,0,255
Oval x1,y1,50,50

WriteLine sendudpstream,LSet(x1,3)+LSet(y1,3)
SendUDPMsg sendudpstream,-1062731774

msg$=RecvUDPMsg(recvudpstream)
x2=Left(msg,3)
y2=Right(msg,3)

Color 0,255,0
Oval x2,y2,40,40
Flip
Wend
End



Dreamora(Posted 2006) [#21]
http://www.blitzbasic.com/codearcs/codearcs.php?code=1593

http://www.blitzbasic.com/codearcs/codearcs.php?code=876

http://www.blitzbasic.com/codearcs/codearcs.php?code=620

There are more under codearchives networking :-)


Steven Noyce(Posted 2006) [#22]
Thanks!
With the help of the second link there, I got it semi-working like this.
Graphics 640,480
SetBuffer BackBuffer()
UDPTimeouts 100
udpstream=CreateUDPStream(4000)

x1=50
y1=50
x2=100
y2=100

While Not KeyDown(1)
Cls
If KeyDown(200) Then y1=y1-2
If KeyDown(208) Then y1=y1+2
If KeyDown(203) Then x1=x1-2
If KeyDown(205) Then x1=x1+2
Color 0,0,255
Oval x1,y1,50,50

WriteLine udpstream,LSet(x1,3)+LSet(y1,3)
SendUDPMsg udpstream,-1062731774,4001

msg=RecvUDPMsg(udpstream)
If msg<>0 Then msgdata=ReadLine(udpstream)
x2=Left(msgdata,3)
y2=Right(msgdata,3)

Color 0,255,0
Oval x2,y2,40,40
Flip
Wend
End

The only problem is, sometimes the other player starts flashing in three different places at once. Does anybody know why?


Steven Noyce(Posted 2006) [#23]
Ok, one other thing I was wondering, what is up with the ports?
Should each joined computer have a different port?
Or should the host have one port and the clients have another?
Which ports are good?
How do I know which number to use?
Should it be 1 or 100 or 4000 or 8000 or 1000000000?
Does it even matter?


Dreamora(Posted 2006) [#24]
< 4000 is no good idea.
I would use 6112, thats blizzard default port and many NAT and firewalls have preset rules for that, that can be activated with 2 clicks.


Steven Noyce(Posted 2006) [#25]
Thanks for the help, but I don't think I understood a single word you said.

What is blizzard?
What is NAT?
Why is having a firewall have preset rules advantageous?
When you say "2 clicks" is that two clicks for me or for the person using my game?
I would need more than one port, wouldn't I? one for the client and one for the host?
I have been using 4000 and it works fine here.

I am so confused!


Wings(Posted 2006) [#26]
If above is not so fun do it in TCP.

Here is a simple sollution for you.. include source.

http://server.voidrpg.com/network test2.rar


Steven Noyce(Posted 2006) [#27]
Thaks, but TCP is WAY to slow for my game. I tried it first with TCP and it would slow down very quickly until it took minutes to transfer data.

Anyway, back to my previous questions.


Wings(Posted 2006) [#28]
well thats cause you probably used instructions like

writeline
writestring
writeint
writelong
writebyte


i too had probles of above commands.

but no more.. now days i use the "writebyetS" instruction.

run several clients of the code above and you see.


Steven Noyce(Posted 2006) [#29]
Thanks, I will try that out.
But, even if your code is a million times better than UDP, I still would like my previous questions answered.


jfk EO-11110(Posted 2006) [#30]
What is blizzard?
This may be a service, like ftp, http or smtp. There are several port reservations, ports that are known to be used by a certain app, like eg. blizzard, whatever it is. What you need is a port list (use google!) that will tell you what ports are used by popular apps, or by trojans (it's bad to use a common trojan port since yor server may look suspicous when a portscanner detects the se sever is listening there)

What is NAT?
Google again said:
http://www.webopedia.com/TERM/N/NAT.html

Why is having a firewall have preset rules advantageous?
A firewall will deny games connections on uncommon ports by default. A user will have to edit the settings of his firewall to allow the game-data pass trough. So when there's a preset, it makes things easier for the players.

When you say "2 clicks" is that two clicks for me or for the person using my game?
Surely for the player. I guess it takes a little more than 2 clicks to make youe MP game working.

I would need more than one port, wouldn't I? one for the client and one for the host?
The client usually may use a any free port, you may even use automatic port choice. Only the server must use a port that is known by the client, to make sure the client can connect. IP and Port is needed to connect to the game sever. THe server at the other hand may answer in a established connection/stream and therefor has no need to know the port of the client.

I have been using 4000 and it works fine here.
4000 may be ok for testing, but before you release anything, get yourself a new port number description aka port list: this one is from iana.org, the official organisation for this kind of matter: http://www.iana.org/assignments/port-numbers
(it's a textfile, so rename to port-numbers.txt when saving)

I am so confused!

me 3!


Steven Noyce(Posted 2006) [#31]
Thanks a bunch!
That was some very useful information!


Steven Noyce(Posted 2006) [#32]
Ok, I think my game is coming along quite nicely now.
One quick question (or mabe not so quick, I don't know),
I timed it, and it takes about 4.5 seconds for my UDP messages to get across the network from one computer to the next.
Is that slow?

If it is normal, I guess I will deal with it.
If not, I will have to try to figure out how to speed it up.


LineOf7s(Posted 2006) [#33]
Um, given that you're going to want to be sending information about each entity in your game potentially many times per second for a non-turn-based game, you may have done something wrong.


Wings(Posted 2006) [#34]
oh almoust forgot..

change the server code a bitt and speed will increese.

Delay 1
;write "."
p=p+1
If p>40 Then Write "." : p=0

this way a paket 40 clients will be transmitted every frame !
making smooth movement of 40 cliets then running on a lan.


jfk EO-11110(Posted 2006) [#35]
4.5 seconds is extremly long. Usually the LAG is the most significant part of the transmission time. Acceptable lags may be 200 millisecs for eg. fps games. But even there the program needs to utilize dead rekoning etc. to allow pseudo-realtime synching.

Try to send only one little packet, containing only about 4 bytes. In a LAN this needs to be sent in a few millisecs.

When testing a client and a server on the same machine, the lag and transmission time may be much higher, because one of the two apps usually has a low priority. Anyway, when using multiple machines in a LAN you should get much better results!

Also, make sure not to kill the server by transmitting repeatedly data, as well as the other way. Instead use a polled timer event that is sending packets only when a certain time has elapsed, regardless of the framerate of the game:

t=millisecs()
if t>= time_for_packet
time_for_packet=t+500
; send packet here...
endif
so this one is sending a packet ever 0.5 seconds.


Steven Noyce(Posted 2006) [#36]
Ok, I timed it wrong. It realy takes 2.25 seconds from one machine to the other. The reason I got 4.5 seconds before was because I would shoot the other player, then it would take 2.25 seconds to get to the other computer that he died, then it would take another 2.25 seconds to get back to my computer that he was dead.

Anyway, this is still appearently way to slow.
So, when you say my packet should be 4 bytes, how many characters in a string is that?

One other question, I am using two computers, but you refrenced testing the client and the server on the same machine. How can you do that?


jfk EO-11110(Posted 2006) [#37]
When you have multiple machines to test things then use it. Running both on one desktop is only a worst case solution. simply run both in windowed mode. Sometimes I had 1 server and 8 clients running on my desktop. Not very efficient tho.

Common Strings based on 8 Bit Ascii use 1 Byte per character. Only Unicode Strings use 2 Bytes, but in Blitz as well as in most simple text apps Ascii is used.

you should not worry too much about the 4 bytes, You could also send an int. I only suggested to search for a fast communication solution first. What's your LAN network, ethernet 10 Mbit cable thing? That should be much faster!

Maybe you should not open a stream for every packet, but re-use established streams.


Steven Noyce(Posted 2006) [#38]
I am not sure what my internet conection speed is. All I know is, it is Quest high speed internet.

As for the 4 byte matter, that might be my problem. I was sending a string that was 110 characters long.


Wings(Posted 2006) [#39]
it sound that you are sending to much.
like the longer you wait to shoot the other player the loooonger lag you will have.

are you having a Laptop vs a desktop. if so maby the laptop have refresh rate at 30mhz and pc has it set at 85 mhz

this diferent will make your program instable with udp. you must check the laptops packages more often.. cause the desktop sending packet with rate. 85 mhz.. and laptop only reading at 30mhz.


like if you have this in your fps code.

flip

test to change it to

flip false
delay 20 ;Delays like 1 frame :)

and see if it gives you less lagg. NOTE this is test only. dont release a code like this !!!


************************
Color 0,255,0
Oval x2,y2,40,40
Flip false ;Make flip dont wait for vblank
delay 20 ;Delay like 1 frame = 20 ms.
Wend
End
****************************


Wings(Posted 2006) [#40]
forgot one think.. see that both computer has 100 mbit lan.
100mbit = 1 ms.. 10 mbit = 10 ms delay


jfk EO-11110(Posted 2006) [#41]
Blitznerd: your internet speed is not the same as your LAN speed. (well at least usually it isn't the same). LAN may be much faster.

Wings, this is confusing me kind of. 1 ms lag? I think the transmission time depends on the packet size. 110 bytes should not be a problem. On a 10 MBit connection you can send about 1 Megabyte per second, for 110 bytes that's about 0.1 milliseconds, or 1000 bytes per millisecond.

Reasonable packet sizes are ~up to about 256 bytes imho, tho the smaller the better, of course.

The lag is caused by a number of factors:

-broadcast gateways etc. delay: when your data is transceived with a pause between receiving and transmitting. This may happen when your connection goes over a high number of internet routers.

-Transmission time. is about the same as your internet speed when playing over the internet, or your LAN speed, when you're playing in the LAN only.

-basicly electronic impolses expand with the speed of light (300'000km/s that's about 130 ms to go around the world. may be ignored in a LAN), so for long distances, this factor should be considered.

-bad programming


The problem of two machines with diffrent hardware power can be solved when you send packets not based on the framerate, but based on the system timer. So you would send the packets say every 200 Millisecs. Example (somewhere in the mainloop):

...
t=millisecs()
if t>t2
t2=t+200
,...send packet
endif

So when a game is running with 60 Hz (17ms/frame) then the packet is sent every (200/17) frames, where on a low machine that can update the screen only say 20 times per second (50ms) th epacket would be sent every (200/50) frames.

However, as I said before, try to find a good connection speed first, regardless of the transmission speed. Transmission speed will be high enough, it's the connection lag (routers, hubs, firewall etc.) that seems your problem (the 2.25 seconds thing)


Wings(Posted 2006) [#42]
i was simple using ping command to determine the 10 and 1 ms speed.

if you ping a gateway on a 10mbit lan it will be like 10 ms to the router.

and if on a 100 mbit lan it nowdays is only 1 ms to router..

i realy dont know why this is ?

maby it depends on 3coms old hardware :)


Steven Noyce(Posted 2006) [#43]
What is "ping command"? What does it do?
Anyway, thanks a bunch jfk!
Very good info that I had no idea about. I will try sending packets based on millisecs instead of framerate. As for the part "try to find a good connection speed", how do I do that? Do I change my programing or like my network connection and stuff?


LineOf7s(Posted 2006) [#44]
You're trying to code a network-multiplayer FPS and you don't know what the 'ping' command is/does?

...

Some reading that might be of interest:

http://www.gamedev.net/reference/articles/article712.asp

http://www.gamedev.net/reference/articles/article1138.asp

http://www.gamedev.net/reference/articles/article722.asp

http://www.blitzbasic.com/codearcs/codearcs.php?code=1593


jfk EO-11110(Posted 2006) [#45]
Wings - ok, I see. I think this is a classical gateway lag. Has not so much to do with the transmission speed, but with the time the data is "relaxing" somewhere in a router chip.

And yes, ping is a good idea to check the real lag between two machines. ping.exe is an msdos command. you may run it from within blitz:

Execfile "command ping 192.168.0.3"

replace 192.168.0.3 by the LAN ip of your 2nd machine.

This will perform 4 pings (note "ping" was used to check for enemy submarines once upon). Ping is a standard service that in theory every internet client or server supports. It is used to check if the distant machine is alive. It's like "hey, are you there?" and the pinged machine should answer "yep, I'm here!". The time the answer takes will be measured.
Ping became a bit unpopular because it was used several times to attack servers, therefor some strict security suites overreact when pinged.


Steven Noyce(Posted 2006) [#46]
Thanks! That looks like it will help a lot! I have to go now, but I will read those articles asap!


Steven Noyce(Posted 2006) [#47]
Ok, I have read the articles, very usefull, so thaks!
Anyway, jfk, I tried your
...
t=millisecs()
if t>t2
t2=t+200
,...send packet
endif

code, but with that, the machines VERY rarely actually received a packet. I have UDPTimeouts set to 0, but apparently I would need a higher number. Any sugestions on how high it should be?


jfk EO-11110(Posted 2006) [#48]
you should receive a packet every 200 milliseconds. you should not send it more often since this is about the ping time you should expect in a internet connection with players from all over the world.

UDP Timeout is ok with the defaults, you don't need to set it. WHen there is no stream to read, the client or server will try again in the next frame.

THere seems to be a connection problem in your LAN. Try the ping.exe, what's the statistics?


Steven Noyce(Posted 2006) [#49]
Ok, I pinged from one computer to the next, and all the requests timed out, which is not surprising, since it times out at 1 second (I think) and it was taking my network 4 seconds to get info back and fourth. Anyway, this is probably not the right forum to ask this, but do you have any idea what could be wrong with my network or how I could fix It?

Both computers are desktops, and one is conected to the internet through the phone lines, while the other is wirelessly conected to that one. The internet is fast and fine on both computers. I am still using port 4000, so is that the problem?

EDIT: But pinging is not conected to the port I use in my game, so that should not effect it.


LineOf7s(Posted 2006) [#50]
If the ping is crapola between your two computers, then every type of network communication will be crapola between them also - including your game.

Debugging your network configuration will be some extra-curricular fun for you, but as far as your game goes, I'd suggest (for the purposes of testing) running the server and the client on the same machine for now.


Steven Noyce(Posted 2006) [#51]
Thanks, I will try that.

What do I put in for the IP addresses? Integer form would be nice.


LineOf7s(Posted 2006) [#52]
127.0.0.1 (as mentioned earlier) is the IP address of the machine the program is running on.

If you want that IP address in integer form, then you'll have to convert it yourself. There's a function to do exactly that in the code archives. Two seconds of looking produced this link.


jfk EO-11110(Posted 2006) [#53]
A firewall sometimes also prevents ping from being answered (eg. zonealarm in the default settings). Unplug your LAN from the internet, then deactivate the firewalls (temporary).


Steven Noyce(Posted 2006) [#54]
Ok, LineOf7s, I tried the link to the code archives that you gave me but I am not sure it works with IP's. Take a look at this.
;the ip adresses of my computer are -1062731773 and 192.168.0.3
;this program SHOULD print 2 of dotted form then two of integer form, but it doesn't
Print inttostr(-1062731773)
Print DottedIP(-1062731773)
Print strtoint("192.168.0.3")
Print "-1062731773"
Delay 4000

Function IntToStr$(num%, strlen% = 4)
	st$ = Chr$(num And 255)
	For shiftin = 1 To (strlen - 1)
		st$ = st$ + Chr$(num Shr (8 * shiftin))
	Next
	Return st$
End Function 

Function StrToInt%(st$)
	For shiftin = 0 To (Len (st$) - 1)
		num = num Or (Asc (Mid$ (st$, shiftin + 1, 1)) Shl shiftin * 8)
	Next
	Return num
End Function

But you don't need to find me other code, I found a different function in the archives that works for this in the UDP chat code.

Anyway, I know practically nothing about networks, so about "Unpluging my LAN from the internet, then deactivating firewalls", I have no idea how to do that. The internet basically IS my LAN, I think. I don't know what firewalls we might have on our computers, so I don't know how to deactivate them. Mabe I will ask my brother (who set up the network), when he comes home next.


LineOf7s(Posted 2006) [#55]
Fair call - looks like I gave you a bum steer. Those functions are for converting your integers to strings and back again, so you can better send it as packets.

Here is the code to convert from a dotted IP address to an integer address from John "Surreal" Arnold's excellent BlitzPlay Lite. I highly recommend it.
Function BP_ConvertIp% (IP$)
;-=-=-=Convert an IP from x.x.x.x to integer format.
	Local dot1 = Instr(IP$,".")
	Local dot2 = Instr(IP$,".",dot1+1)
	Local dot3 = Instr(IP$,".",dot2+1)
	Local Octet1% = Mid$(IP$,1,dot1-1)
	Local Octet2% = Mid$(IP$,dot1+1,dot2-1)
	Local Octet3% = Mid$(IP$,dot2+1,dot3-1)
	Local Octet4% = Mid$(IP$,dot3+1)
	Return (((((Octet1 Shl 8) Or Octet2) Shl 8) Or Octet3) Shl 8) Or Octet4
End Function


That being said though, if you "know practically nothing about networks", then perhaps writing a "multiplayer first person shooter using UDP" is more than a little beyond you just for now?

(I'm trying to be as diplomatic as possible)


Steven Noyce(Posted 2006) [#56]
Thanks for the code! Works like a charm!

I know that this project is a bit over my head, but it is coming a long quite nicely! I also think that this is a common question, so maybe the whole comunity could benifit from this thread. I will post code and media when I think it works pretty well, and I think that a LOT of beginners wanting to make this sort of thing would be very gratefull for this kind of "No nothing about multiplayer or UDP and want to learn fast" type of thread. I don't know, maybe no one will find this usefull, but I sure have learned alot about how to do this! Thanks everbody for your excelent help! I will keep working on this and probably have some more questions later, but for now, I need to wait until my brother comes home to have him help me get the network working better, but I mainly just need to find a bit more time to work on it!

I'll be in touch!


LineOf7s(Posted 2006) [#57]
Test it on one machine first. Get the network code working, so when you try it on a proper network you'll know it's the network that's not working properly rather than your code.


Steven Noyce(Posted 2006) [#58]
On one machine, will it take a lot less time for messages to get to their destination? Will packets ever be dropped or lost? If not, should I try to simulate these effects or just ignore them?


LineOf7s(Posted 2006) [#59]
On one machine, ping times should be as low as 5ms or less. No packets should be lost, no - but once you put something together that works, you'll want to simulate packet loss so you can make your game code robust enough to deal with it (since it *will* happen in the real world).

Not something you need to worry about to begin with though. Step one is to get it working at all. Step two is to get it working well.

And even if you don't want to use it as a library unto itself (and you should), you should download BlitzPlay Lite and go through the various functions built in to see how it does things. Then if you still want to do it from scratch, at least you have a working codebase to learn from.


Steven Noyce(Posted 2006) [#60]
Here is my game so far. I know that it is not very impressive, but hey, I am just learning!
Anyway, here it is! I will post code later.
http://www.freewebs.com/blitznerd/FPS/UDP_FPS_2.zip