VERY basic networking code?

Blitz3D Forums/Blitz3D Programming/VERY basic networking code?

bytecode77(Posted 2007) [#1]
hi!

i am looking for a networking code (upd)
i didnt quite understand how it works and i tested some samples. what i need is a very very basic code how to communicate with a server.

any ideas?

thanks :)


b32(Posted 2007) [#2]
I tried only BlitzPlay, and it works okay. To find UDP samples, have you tried searching for "CreateUDPStream" ?
http://www.google.com/search?hl=en&q=createudpstream&btnG=Search
or
http://www.google.com/search?hl=en&q=createudpstream+blitz3d&btnG=Google+Search


bytecode77(Posted 2007) [#3]
i hunted down the whole forum searching for udp and createudpstream.

none of these samples were working between my two computers.
(i know that i successfuly established a connection. i was able to transfair)


bytecode77(Posted 2007) [#4]
okay, i found something that actually works. gnet! i tested it and i was able to create a server. but how can a client join the server?

ps: my firewall is not a problem. i tested it with counterstrike


jfk EO-11110(Posted 2007) [#5]
Actually there is no "very simple" udp netcode. The reason why is: UDP is a very basic transmission method. It has no error checks and is not packet oriented etc. It's like a wire in space, nothing more, and the whole transfer protocol must be coded by the programmer, eg. morse or something.

So a Multiplayer netcode may contain 2 parts: the UDP netcode that handles the game between the players, and some TCP code that is connecting to a webserver that stores all neccessary infos to allow people to join the game. So imagine on www.DCs_game.com there could be gnet running, or maybe something you used to write by your own (probably using Gnet as basement). A player will connect to the webserver, receive the IP of the UDP game server, what ports are used, what people are already there, how long the game is already running etc etc.

Then he may join the game as a client. The game (udp) host will then update the infos on the webserver.

Let's have a look at the UDP part only. First you have to design a packet system. Every packet should contain a purpose ID, a sequence number and an encrypted integrity checksum. These numbers should be part of the header.

The purpose ID allows the receiver to decide how to use the packet, examples: a join-request packet, a player-data packet, a player leaving packet, a chat packet...

The sequence number allows the receiver to detect missing packets. So when he receives packet 24 and then packet 26, he should send a reorder-packet that asks for packet 25.

The integrity checksum is a checksum of the rest of the packet and allows to compare a checksum that is created locally to be compared with it. If the 2 checksums are not the same, there must be some error in the packet and it should be reordered as well.

Probably the header should also contain information about the packet lenght.

Then there should be acknowledge packets that are used as a handshake, after a successfully delivered packet. These ack packets are the only packets that don't need an ack packet (because this would result in an endless loop of ack packets)

The whole "player join, add to list" etc. logic should be coded by the programmer, as well as all other things, like chat packets and so on. I even added a host-takeover packet that allows the host to quit the game without to end the game. In this case, the player with the next best ping will become the new game host automaticly. This requires a randomly created password that is handed over during the host takeover.

You see, there is no very easy netcode. Depending on the situation, you maybe should try one of the existing libs, like BlitzPlay or so.

BTW. when you connect to a webserver, this may pause the game if you wait for the answer of the webserver. Instead you should simply send the infos to the webserver and then close the stream.

Ehrm - maybe your question wasn't about all this stuff, but simply on how to make UDP work at all. Also make sure if there's a router between the machines, they may alter the port numbers, see this thread: http://www.blitzbasic.com/Community/posts.php?topic=68202


bytecode77(Posted 2007) [#6]
first: thank you for that fast and long reply! thats what i'm calling support :)

but then, on another topic: i know how to write a serverlist using php. what i dont know, is how to connect via ip to a udp server
CreateUDPStream([Port%])
;shouldnt it be this way:
CreateUDPStream(ip$)


this is what i just dont understand. you're connecting to a port? but hell knows where your packages land? why cant i connect to an ip? it sounds logical to connect to an ip...
i asked arround in my family and wikipedia before i wrote here, and they couldn't get me going on this.

i hope you do


Naughty Alien(Posted 2007) [#7]
I would suggest NetBlitz..its free, its UDP based its fast and support for much players as your hardware can maintain...excellent..


bytecode77(Posted 2007) [#8]
thank you guys. i'll try netblitz.
if i have questions, i will bother you again :)
thanks!


jfk EO-11110(Posted 2007) [#9]
DC, CreateUDPStream is not really sending data or receiving data, it simply makes a local port ready for action.

Look at the SendUDPMsg command, it takes an IP (and port) parameter. This may be a known host IP and port (taken from a webserver maybe), or if this is an answer to a (yet) unknown client that has sent data to the host (host may use ReadAvail and ReadBytes) then you may use UDPMsgIP and UDPMsgPort to obtain the correct return adress for SendUDPMsg for the answer from host to client.

So basicly, the host may receive and send using the same stream handle. Before you send data using sendUDPMsg, you need to write it to the buffer using a standard stream command, as if it was a file, example:

WriteInt mystream, 314159
sendUDPMsg mystream, UDPMsgIP(mystream),UDPMsgPort(mystream)

Hope this helps.


octothorpe(Posted 2007) [#10]
...how to connect via ip to a udp server


Maybe this will help clear things up: you don't connect to a UDP server.

TCP has "connections" which are established through handshaking packets and provide the organization required to ensure messages are retransmitted if lost, and provided in the right order.

UDP is dirt simple, it just sends single packets to IP addresses. No connections and no guarantees about delivery. You could code some super-reliable UDP client/server code, but you'd basically be re-implementing TCP.

Do you absolutely need to use UDP? TCP is easier to use. Later, if you decide that TCP isn't quick enough for some traffic, you can switch some (possibly redundant) communications over to UDP, while continuing to use TCP for stability.


jfk EO-11110(Posted 2007) [#11]
Personally I think implemeting a transfer protocol on a low level like UDP is pretty entertaining. It allows to do some custom optimizations in the first place. It's also a good exercise for an abstraction-layer oriented implementation of a program.


octothorpe(Posted 2007) [#12]
"Premature optimization is the root of all evil."


bytecode77(Posted 2007) [#13]
i tested this all and i barely gave up all hope.
does anyone have a sample where just two pcs with given ip adresses are communicating?
thank you so much!!


Naughty Alien(Posted 2007) [#14]
..did you try NetBlitz?? Within package you have exactly what you are looking for..nice 3D demo with PC's communicating and each player driving around one ball..


bytecode77(Posted 2007) [#15]
netBlitz didnt work.
what i really need to learn it is one little demo where just two pcs with given ips are sending packages. that is all :)


ZJP(Posted 2007) [#16]
K-NetLib here. http://www.krylarskreations.com/knl.shtml
Simple and free.


bytecode77(Posted 2007) [#17]
it is working, but i just dont understand why people always do the same mistake and make some long code. are there samples of knet which are less than 100 lines?


Vertigo(Posted 2007) [#18]
Most if not all of those demos should work DC. I dont think they would release all of these packages if they were broken. If you are having problems with connections, maybe you should read up more on networking in general. Chances are you have an issue with your router. I dont know what ports and protocols counter strike uses... but just because it gets passed through NAT doesnt mean that your personal program will. Thats like saying, I can open aim on my pc, why cant I vpn to my home computer from china. haha. Also a lot of routers have what is called "UDP packet scanning" "Denial of Service" "Packet flood inspection" among other things. These options will chop the headers or udp streams and cause chaos with any "near" constant connection. Id bet all of those apps work. Check your home network. Also why such haste?


bytecode77(Posted 2007) [#19]
counterstrike and knet were working. my issue, is that knet is too much of code. i'm looking for a rather slim knet code


jfk EO-11110(Posted 2007) [#20]
Did you try my example?

(>
...
WriteInt mystream, 314159
sendUDPMsg mystream, UDPMsgIP(mystream),UDPMsgPort(mystream)
...
)

Maybe you should test it on localhost first, using two windows on your desktop, one client and one host. They need to use unique Ports, of course. If this works then it must be something with your router.

Post the miminal test code that didn't work.


Naughty Alien(Posted 2007) [#21]
I'm not sure that you can make quality network program with few lines of code..and as Vertigo said, things working for sure (as well as NetBlitz), its up to your local network configuration..on my side working just fine same as BlitzPlay, after i realized problem with my router...


Ching(Posted 2007) [#22]
Can someone tell me why bother using UDP when direct play is part and parcel of Blitz3d?
I have created network games that use direct play features and its easy peasy.
Having said that where is all the info about Gnet?


bytecode77(Posted 2007) [#23]
the blitz3d directplay is based on tcp, which makes it 3-4 times slower than udp. also its very user-unfriendly and does not work well in fullscreen mode.

gnet is good, except, that there is no small example...


semar(Posted 2007) [#24]
Would my tutorial be of any help for you ? It's a complete internet/LAN chat program, you find the server and client source code in the code archive:

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

Sergio.


Litobyte(Posted 2007) [#25]
Please can you guys have a look here:
http://www.blitzbasic.com/en/Community/posts.php?topic=31510
(see the last post of the topic)

and try to help me !!?

Please, please, please, I'm stuck!

Thank you


cash(Posted 2007) [#26]
I havent read all the responses so it may have been mentioned but. If you have a windows firewall or another firewall enabled you will need to ensure it allows the traffic IN on both machines.

If you switch off the windows firewall on both machines this will temporarily tell you if they communicate. Don`t be connected to the internet while you do this as you will be exposed. If it works then you will need to re-enable the firewall and find the ports used by the software and create explicit rules.