Can a Network game be played over the internet or does it have to be on a network.
Network Game
Blitz3D Forums/Blitz3D Programming/Network Game The internet *IS* a network, so of course the answer is yes.
IMHO that's a bit short sighted. Theoreticly it may be the same, practicly there are differences:
* NAT, Firewalls
* slower connections (if the game is LAN only you might not need to optimize data transfer as much)
* Greater distances require good netcoding, e.g prediction.
* NAT, Firewalls
* slower connections (if the game is LAN only you might not need to optimize data transfer as much)
* Greater distances require good netcoding, e.g prediction.
@Blitz Programmer,
I agree with the other posters here. Only one thing, yes Internet is a network, but the DirectPlay commands won't work.
If you want to play in internet, you have to use TCP or UDP. If you want to play in LAN, you can use also DirectPlay.
Bare in mind that the speed of these three protocols is different; for example, DirectPlay is very reliable, but really slow. TCP is also reliable, and faster than Directplay.
UDP is the fastest you can use, but not reliable, which means, a sent UDP packet could be lost in space, or arrive at destination not exactly in the same order it was sent, in respect with the other packets.
DirectPlay and TCP are great for turn-based games, UDP is the way to go for fast paced action games. I use UDP in BomberLAN, a remake of Amigas Bomberman, and in LAN it works really smooth.
Sergio.
I agree with the other posters here. Only one thing, yes Internet is a network, but the DirectPlay commands won't work.
If you want to play in internet, you have to use TCP or UDP. If you want to play in LAN, you can use also DirectPlay.
Bare in mind that the speed of these three protocols is different; for example, DirectPlay is very reliable, but really slow. TCP is also reliable, and faster than Directplay.
UDP is the fastest you can use, but not reliable, which means, a sent UDP packet could be lost in space, or arrive at destination not exactly in the same order it was sent, in respect with the other packets.
DirectPlay and TCP are great for turn-based games, UDP is the way to go for fast paced action games. I use UDP in BomberLAN, a remake of Amigas Bomberman, and in LAN it works really smooth.
Sergio.
If you want to create internet capable games, use BlitzPlay, its super simple and more than fast enough for just about anything. As far as Direct Play, it also works over TCP/IP, didn't used to, but I believe in DX6 they made the mover from only IPX/SPX to adding TCP/IP support also. However, Direct Play does not do well with NAT based firewalls and is really a joke by todays standards anyway. BlitzPlay Pro will do everything you want and will only take you a day or two to get familure with.
Of course you could hammer out your own netcode, but then you wouldn't really be making efficiant use of your time, spending hours writing code that is already available, when you could instead be writing code for your game. :)
OK, I can see reinventing the wheel for educational reasons or even self satisfaction, but don't do it because your a purist. LOL
Of course you could hammer out your own netcode, but then you wouldn't really be making efficiant use of your time, spending hours writing code that is already available, when you could instead be writing code for your game. :)
OK, I can see reinventing the wheel for educational reasons or even self satisfaction, but don't do it because your a purist. LOL
Check Jeremy Allessi's great Code Example in the Code Archive. It's a full internet capable multiplayer game.
Your not reinventing the wheel, your just adding 1 more degree to a full circle :P
I want to play a game I made with a friend. I'm trying to see if TCP or UDP or DirectPlay would be better. Its a shooter game so it sends the pos of the enemy,join msg,mail,reset a player,Quit,Win/lose. the pos of the enemy is sent every frame.
I've found BlitzPlay very easy to implement, so you might want to check that out. There's a free version and a paid version, but I've only tried the paid version so I don't know how full-featured the free version is.
http://www.blitzcoder.com/blitzplay
http://www.blitzcoder.com/blitzplay
I'm having a problem with multiple enemys. It won't display any enemies when somebody joins.
AppTitle "Internet Game" SetBuffer BackBuffer() Type EnemyType Field Name$ Field mesh Field Id End Type SeedRnd MilliSecs() Global Game = StartNetGame() If Game = 0 Then End EndIf Graphics3D 1024,768,32,1 Global Name$ = Input$("Enter Your Name: ") FlushKeys() FlushMouse() FlushJoy() id = CreateNetPlayer(Name$) If Game = 1 Then SendNetMsg 1,Name$,id,0,False EndIf Cls Dim sight(2) sight(0) = LoadImage("Sight.bmp") sight(1) = 0 Building = LoadMesh("Building2-5.b3d") ;RotateEntity Building,Rand(0,360),Rand(0,360),Rand(0,360) Dim bullet(5) enemy = LoadMesh("Person.3ds") bullet(0) = LoadMesh("Bullet.3ds") HideEntity enemy EntityType enemy,3 EntityType bullet(0),4 HideEntity bullet(0) players = 0 If Building = 0 Then RuntimeError "File: 'Building.b3d' Not Found" EndIf Collisions 1,2,2,2 Global player = CreatePivot() PositionEntity player,0,1,0 EntityRadius player,.3 EntityType player,1 Global box = CreateCube() ResizeMesh(box,1,1,1) Randomize() Global camera = CreateCamera(player) CameraRange camera,.1,200 Global light = CreateLight() LightColor light,32,32,32 TurnEntity light,45,-45,0 EntityFX Building,1 EntityType Building,2 sp#=.05 ey#=EntityY(player) While Not KeyHit(1) yv#=EntityY(player)-ey ey=EntityY(player) If KeyHit(57) yv=.1 MoveEntity player,0,yv-.005,0 If KeyHit(31) sight(1) = Not sight(1) If MouseHit(1) ShowEntity bullet(0) bullet(1) = EntityX(player) bullet(2) = EntityY(player) bullet(3) = EntityZ(player) bullet(5) = 1 PointEntity bullet(0),sight(0) PositionEntity bullet(0),bullet(1),bullet(2),bullet(3) EndIf If KeyDown(30) TurnEntity camera,-2,0,0 If KeyDown(44) TurnEntity camera,+2,0,0 If KeyDown(203) TurnEntity player,0,2,0 If KeyDown(205) TurnEntity player,0,-2,0 If KeyDown(200) MoveEntity player,0,0,sp If KeyDown(208) MoveEntity player,0,0,-sp Distance = EntityDistance(player,box) If frame = 25 Then SendNetMsg 2,EntityX(player) + "," + EntityY(player) + "|" + EntityZ(player),id frame = 0 EndIf frame = frame + 1 RecvNetMsg() If NetMsgType() = 2 Then start = Instr(NetMsgData(),",") x = Left(NetMsgData(),start - 1) start2 = Instr(NetMsgData(),"|") y = Mid(NetMsgData(),start + 1,start2 - 1) z = Right(NetMsgData(),Len(NetMsgData()) - start2) For thisEnemy.EnemyType = Each EnemyType If thisEnemy\Id = NetMsgFrom() Then PositionEntity thisEnemy\mesh,x,y,z EndIf Next EndIf CheckMail() Locate 0,0 Print EntityDistance(player,box) RecvNetMsg() If Game = 2 And NetMsgType() = 4 And NetMsgData$() = "Get" Then SendNetMsg(4,"Send: " + Players,NetMsgFrom()) EndIf If NetMsgType() = 99 Then Cls Locate 0,0 Print "You lost. " + NetMsgData() + " Won!" EndGame() EndIf If EntityDistance(player,box) < 1 Then Cls Locate 0,0 Print "You Won!!!" SendNetMsg 99,Name$,id Delay 500 EndGame() EndIf If EntityDistance(player,enemy) =< 0.5 And 1 = 2 Then SendNetMsg( 99,Input$("Who was that?"),id) EndIf UpdateWorld RenderWorld Print "Frame: " + frame If sight(1) = 1 Then DrawImage sight(0),MouseX(),MouseY(),0 EndIf Flip Wend SendNetMsg 98,Name$,id EndGame() End Function ResizeMesh(mesh,width#,height#,depth#) ScaleMesh mesh,1/MeshWidth#(mesh)*width#,1/MeshHeight#(mesh)*height#,(1/MeshDepth#(mesh))*depth# End Function Function EndGame() FreeEntity Building FreeEntity box FreeImage sight(0) EndGraphics End End Function Function CheckMail() RecvNetMsg() If NetMsgType() = 1 Locate 0,0 Print NetMsgData() + " has joined" players = players + 1 Print "Increase player amount" thisEnemy.EnemyType = New EnemyType Print "Created new player type" thisEnemy\mesh = CopyMesh(enemy) thisEnemy\Name$ = NetMsgData() thisEnemy\Id = NetMsgFrom() Delay 1000 EndIf If NetMsgType() = 97 Then If NetMsgData = Name$ Then PositionEntity player,0,1,0 EndIf EndIf End Function Function Randomize() Select Rand(0,6) + 1 Case 1 PositionEntity box,-7,0,-7 Case 2 PositionEntity box,19,0,-18 Case 3 PositionEntity box,18,4,-18 Case 4 PositionEntity box,25,-3,-10 Case 5 PositionEntity box,5,-2,22 Case 6 PositionEntity box,Rand(-8,30),0,Rand(-22,26) Case 7 PositionEntity box,27,6,3 End Select End Function ;Msg Types ;1 = Join ;2 = Position ;3 = Mail (Send a msg) ;4 = Request Player amount ;97 = Reset Player ;98 = Quit ;99 = Win/Lose
I've got it working so that you can create players and others stuff. My positioning system isn't working. The enemy will appear 0,0,0 but won't moveafter that.
This is where the pos code is
P.S. This is my 100th post!!!
AppTitle "Internet Game" SetBuffer BackBuffer() ;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;Types;;;;;;;; ;;;;;;;;;;;;;;;;;;;;; Type EnemyType Field Name$ Field mesh Field Id End Type Type BulletType Field mesh End Type SeedRnd MilliSecs() Global Game = StartNetGame() If Game = 0 Then End EndIf Graphics3D 1024,768,32,1 Global Name$ = Input$("Enter Your Name: ") ;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;Arrays;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;; Dim sight(2) ;Load Required Data Global BulletMesh = LoadMesh("Bullet.3ds") Global GunFire = LoadSound("gunfire.wav") sight(0) = LoadImage("Sight2.bmp") Building = LoadMesh("Building2-6.b3d") Global enemy = LoadMesh("Person.3ds") ;Clear all button history FlushKeys() FlushMouse() FlushJoy() id = CreateNetPlayer(Name$) If Game > 0 Then SendNetMsg(1,Name$,id) ElseIf Game = 1 Then SendNetMsg(4,"Request: Host Player",id) Repeat RecvNetMsg() If NetMsgType() = 4 Then thisEnemy.EnemyType = New EnemyType thisEnemy\Name$ = Mid$(NetMsgData$(),9,Len(NetMsgData$())) thisEnemy\Id = NetMsgFrom() thisEnemy\mesh = CopyMesh(enemy) EndIf Until NetMsgType() = 4 EndIf Cls HideEntity BulletMesh sight(1) = 0 MidHandle sight(0) ;RotateEntity Building,Rand(0,360),Rand(0,360),Rand(0,360) HideEntity enemy EntityType enemy,3 EntityType bulletMesh,4 If Building = 0 Then RuntimeError "File: 'Building.b3d' Not Found" EndIf Collisions 1,2,2,2 Global players Global player = CreatePivot() PositionEntity player,0,1,0 EntityRadius player,.3 EntityType player,1 Global box = CreateCube() ResizeMesh(box,1,1,1) Randomize() Global camera = CreateCamera(player) CameraRange camera,.1,200 Global light = CreateLight() LightColor light,32,32,32 TurnEntity light,45,-45,0 EntityFX Building,1 EntityType Building,2 sp#=.05 ey#=EntityY(player) While Not KeyHit(1) yv#=EntityY(player)-ey ey=EntityY(player) If KeyHit(57) yv=.1 MoveEntity player,0,yv-.005,0 If KeyHit(31) sight(1) = Not sight(1) If KeyDown(30) TurnEntity camera,-2,0,0 If KeyDown(44) TurnEntity camera,+2,0,0 If KeyDown(203) TurnEntity player,0,2,0 If KeyDown(205) TurnEntity player,0,-2,0 If MouseDown(1) And sight(1) thisbullet.BulletType = New BulletType thisbullet\mesh = CopyMesh(bulletMesh) RotateEntity thisBullet\mesh,EntityPitch(player,1),EntityYaw(player,1),EntityRoll(player,1) PlaySound GunFire PositionEntity thisBullet\Mesh,EntityX(player),EntityY(player),EntityZ(player) EntityType thisbullet\Mesh,3 EndIf If KeyDown(200) MoveEntity player,0,0,sp If KeyDown(208) MoveEntity player,0,0,-sp Distance = EntityDistance(player,box) For biter.BulletType = Each BulletType MoveEntity biter\mesh,0,0,1 If Abs(EntityX(biter\mesh,1)) > 1000 FreeEntity biter\mesh Delete biter ElseIf Abs(EntityY(biter\mesh,1)) > 1000 FreeEntity biter\mesh Delete biter ElseIf Abs(EntityZ(biter\mesh,1)) > 1000 FreeEntity biter\mesh Delete biter EndIf Next If frame = 25 Then SendNetMsg 2,EntityX(player) + "," + EntityY(player) + "|" + EntityZ(player),id frame = 0 EndIf frame = frame + 1 RecvNetMsg() If NetMsgType() = 2 Then start = Instr(NetMsgData(),",") x = Left(NetMsgData(),start - 1) start2 = Instr(NetMsgData(),"|") y = Mid(NetMsgData(),start + 1,start2 - 1) z = Right(NetMsgData(),Len(NetMsgData()) - start2) For thisEnemy.EnemyType = Each EnemyType If thisEnemy\Id = NetMsgFrom() Then PositionEntity thisEnemy\mesh,x,y,z EndIf Next EndIf TurnEntity player,0,-MouseXSpeed(),0 CheckMail() If KeyDown(54) Then sp# = 2 ElseIf KeyDown(42) Then sp# = .2 Else sp# = .05 EndIf Locate 0,0 Print EntityDistance(player,box) Print "Frame: " + frame RecvNetMsg() If NetMsgType() = 1 Locate 0,0 Cls Print NetMsgData() + " has joined" players = players + 1 Print "Increase player amount" thisEnemy.EnemyType = New EnemyType Print "Created new player Type" thisEnemy\mesh = CopyMesh(enemy) thisEnemy\Name$ = NetMsgData$() thisEnemy\Id = NetMsgFrom() Delay 1000 EndIf If NetMsgType() = 98 Then Print NetMsgData$() + " has quit the game" For thisEnemy.EnemyType = Each EnemyType If thisEnemy\Id = NetMsgFrom() Then FreeEntity thisEnemy\mesh Delete thisEnemy EndIf Next EndIf If Game = 2 And NetMsgType() = 4 And NetMsgData$() = "Get" Then SendNetMsg(4,"Send: " + Players,NetMsgFrom()) EndIf If NetMsgType() = 99 Then Cls Locate 0,0 EndGraphics Print "You lost. " + NetMsgData() + " Won!" Delay 500 EndGame() EndIf If EntityDistance(player,box) < 1 Then Cls Locate 0,0 EndGraphics Print "You Won!!!" SendNetMsg 99,Name$,id Delay 500 EndGame() EndIf UpdateWorld RenderWorld If sight(1) = 1 Then DrawImage sight(0),GraphicsWidth() / 2,GraphicsHeight() / 2,0 EndIf Flip Wend SendNetMsg 98,Name$,id EndGame() End Function ResizeMesh(mesh,width#,height#,depth#) ScaleMesh mesh,1/MeshWidth#(mesh)*width#,1/MeshHeight#(mesh)*height#,(1/MeshDepth#(mesh))*depth# End Function Function EndGame() FreeEntity Building FreeImage sight(0) DeleteNetPlayer id EndGraphics End End Function Function CheckMail() RecvNetMsg() If NetMsgType() = 4 And NetMsgData$() = "Request: Host Player" Then SendNetMsg(4,"Return: " + Name$,id) EndIf If NetMsgType() = 97 Then If NetMsgData = Name$ Then PositionEntity player,0,1,0 EndIf EndIf If NetMsgType() = 200 Then Locate 0,0 DeleteNetPlayer id RuntimeError "A Fatal Error Occurred" EndGame() EndIf End Function Function Randomize() Select Rand(0,6) + 1 Case 1 PositionEntity box,-7,0,-7 Case 2 PositionEntity box,19,0,-18 Case 3 PositionEntity box,18,4,-18 Case 4 PositionEntity box,25,-3,-10 Case 5 PositionEntity box,5,-2,22 Case 6 PositionEntity box,Rand(-8,30),0,Rand(-22,26) Case 7 PositionEntity box,27,6,3 End Select End Function ;Msg Types ;1 = Join ;2 = Position ;3 = Mail (Send a msg) ;4 = Request ;97 = Reset Player ;98 = Quit ;99 = Win/Lose
This is where the pos code is
If NetMsgType() = 2 Then start = Instr(NetMsgData(),",") x = Left(NetMsgData(),start - 1) start2 = Instr(NetMsgData(),"|") y = Mid(NetMsgData(),start + 1,start2 - 1) z = Right(NetMsgData(),Len(NetMsgData()) - start2) For thisEnemy.EnemyType = Each EnemyType If thisEnemy\Id = NetMsgFrom() Then PositionEntity thisEnemy\mesh,x,y,z EndIf Next EndIf
P.S. This is my 100th post!!!
I can't help - don't have a clue what network play is about... :(
Whats the point in posting then ;)
dammit, oh the irony :D
dammit, oh the irony :D
Are you sure you are sending the Global position in and not the movement info relative to the enemies last position? This is a common misstake.
Since Moveentity is based on movement from the relative position and facing, the values used there are no use to positionentity. What you want to make sure you are sending is, EntityX, EntityY and EntityZ, as well as the yaw, pitch, roll of the same type, if you use those.
I see you are sending the EntityX(player) etc. However you may want to try sending EntityX(player,1) and then use positionentity with the global flag set for data recieved from the net.
Just a idea, you may want to coment some of that code so its a tad easier to see what your trying to achieve, would make debugging alot easier. :)
Since Moveentity is based on movement from the relative position and facing, the values used there are no use to positionentity. What you want to make sure you are sending is, EntityX, EntityY and EntityZ, as well as the yaw, pitch, roll of the same type, if you use those.
I see you are sending the EntityX(player) etc. However you may want to try sending EntityX(player,1) and then use positionentity with the global flag set for data recieved from the net.
Just a idea, you may want to coment some of that code so its a tad easier to see what your trying to achieve, would make debugging alot easier. :)
Ok, I am a network noob also.
How does blitz know what todo with the incoming data. Say i stream the xyz co-ords
34 56 21, how does blitz know thats the xyz and put it the right type field to then act on it?
How does blitz know what todo with the incoming data. Say i stream the xyz co-ords
34 56 21, how does blitz know thats the xyz and put it the right type field to then act on it?
Well I would place a stop in the if test after the Type thisEnemy\ID test, to make sure you are getting to the PositionEntity, just creating the mesh will position it at 0,0,0, so if that test fails they will always stay at the creation point.
If thisEnemy\Id = NetMsgFrom() Then
stop
.
.
.
end if
Actually, if you are only supporting 1 other player, you dont really need to test for anything but NULL and just perfrorm the position every frame.
Again just some ideas.
If thisEnemy\Id = NetMsgFrom() Then
stop
.
.
.
end if
Actually, if you are only supporting 1 other player, you dont really need to test for anything but NULL and just perfrorm the position every frame.
Again just some ideas.
ok Blitz Programmer, so say the message is sent like:
21,23|43 (if i read your example correctly) and the other side (say server) get its
How do you then find out if that piece of information is the co-ords? Rather than something say, the animation of the character?
I could understand putting in 2 leading characters such as
PL,21,23,43 Then sending that as a string, then when receaving it looking fr the 2 leading characters and processing it like that.
Does this make sence?
21,23|43 (if i read your example correctly) and the other side (say server) get its
How do you then find out if that piece of information is the co-ords? Rather than something say, the animation of the character?
I could understand putting in 2 leading characters such as
PL,21,23,43 Then sending that as a string, then when receaving it looking fr the 2 leading characters and processing it like that.
Does this make sence?
Yes. I set the NetMsgType to 2 which is the msgtype for position. There isn't a server really. The first player is the server but it doesn't sit there and watch, the server/player plays.
@Strider Centaur
I had it so that only one other player could join but now I want it to have mutiple players at once so that other people can play.
@Strider Centaur
I had it so that only one other player could join but now I want it to have mutiple players at once so that other people can play.
I see, and if I was not using the direct play method (say I was using the tcp stream) is using leading characters the best way?
Really I need to know how to package my data for it to be sent, then unpack it to process it
would a good way be to send it looking something like this
"Bob,32,24,53,0,0,42"
Then untankle it?
Really I need to know how to package my data for it to be sent, then unpack it to process it
would a good way be to send it looking something like this
"Bob,32,24,53,0,0,42"
Then untankle it?
You could. I'm not that great at TCP though. I did write a program to send mail. I tried the make a new IP address on my network but that didn't work. I can do BlitzPlay sorta well.
Client
Server
Client
tcp=OpenTCPStream("192.168.2.85",2000) ;msg type,x,y,z WriteLine tcp,"2/20|30\30"
Server
tcp=CreateTCPServer(2000) Type = AcceptTCPStream(tcp) ;Uncode here
Is DirectPlay that bad? I did some ping/bandwidth tests a while back with DirectPlay and BlitzPlay doing Tennessee to Georgia and they performed just about the same.
I think BlitzPlay(BP) is just easier to use over all. For one BP seems to handle NAT much better on the client side.
@Blitz Progeammer
Getting more than one to work is as easy as getting one to work, just make sure your players are defined in types and spawn a new instance of that type. Just use the player ID to track what message should update what player. Then loop through all the players in the type list with the good ole "For typename.type = each type ..... Next" loop and perform the updates.
One nice thing BP offers is a spline routing to help deal with lag delays. Also support for Gnet that makes finding a server much nicer. :)
@Blitz Progeammer
Getting more than one to work is as easy as getting one to work, just make sure your players are defined in types and spawn a new instance of that type. Just use the player ID to track what message should update what player. Then loop through all the players in the type list with the good ole "For typename.type = each type ..... Next" loop and perform the updates.
One nice thing BP offers is a spline routing to help deal with lag delays. Also support for Gnet that makes finding a server much nicer. :)
Can you use UDP and TCP both in the same session? I.E. use UDP for info that needs to get there quick and TCP for info that can be a bit late but MUST arrive?
You could open UDP and TCP and the client would have to connect to both. The client would have to check both. I don't know if it would work but it might.
Yes you can mix UDP and TCP, but would need to use 2 ports. One port for TCP and the other port for UDP. Then you would have to read each port seperatly. This does not mean you would need to create 2 totally seperate messaging scheams( codes ), you could simple call your NetHandler(Message) function after reading in a stream from either port. This is as long as you keep the message format consistant.
Okay... not sure when that might be appropriate but who knows?
I looked through the online B3D manual last night and the network commands are documented awfully! I couldn't make head nor tail of them - the manual could do with a separate tutorial on network coding. I looked elsewhere online for tutorials and found a few articles on demaster.org, but I still don't really understand what a port actually is and how it works.
I looked through the online B3D manual last night and the network commands are documented awfully! I couldn't make head nor tail of them - the manual could do with a separate tutorial on network coding. I looked elsewhere online for tutorials and found a few articles on demaster.org, but I still don't really understand what a port actually is and how it works.
Save yourself time and frustration and get BlitzPlay, Surreal has done a awesome job of making Net Coding easy. There is a Lite version which will probably do everything you will want in a game. But if you find it usefull, please help support Surreal by buying the PRO version. :)
Heres the URL
http://www.blitzcoder.com/blitzplay/
Heres the URL
http://www.blitzcoder.com/blitzplay/
I looked through the online B3D manual last night and the network commands are documented awfully! I couldn't make head nor tail of them - the manual could do with a separate tutorial on network coding. I looked elsewhere online for tutorials and found a few articles on demaster.org, but I still don't really understand what a port actually is and how it works.
Yeah. Tell me.
The examples dont seem to make it much easier either.
but I still don't really understand what a port actually is and how it works.
I don't think it's up to the blitz manual to point out the basics of networking. After all, the manual doens't explain how to do other basic things like clicking your mouse either.
Anyway, a port is just a number that is used by the computer to identify which program it has to send the data to.
For instance, if you have a webserver program running and you've got it configured to listen to port 80 (default for web), and browser makes a connection to your computer on port 80, your computer will send it to the webserver program.
Hmm, a port is just a way to identify a buffer in the network sub systems.
It is evem possible to have multiple apps looking at the same port at the same time, but this is highly unusuall. Examples of this are Sniffers that analyze all ports, transparantly.
For TCP/IP and UDP all you really need is the IP address and a port to connect to. The Server Listens to connections to a port and the client make connections to a remote port.
If you really want to get way to deep into TCP and the other things related like ICMP and what not, you may want to check out "UNIX Network Programming", an excelent book on the subject. Its usually a big white book with blue letters.
That book covers pretty much everything, along with example "C" source code to see how things are handled in code.
I know its UNIX, but once you understand that, then you can tackle any SOCK interface ever made real easy.
It is evem possible to have multiple apps looking at the same port at the same time, but this is highly unusuall. Examples of this are Sniffers that analyze all ports, transparantly.
For TCP/IP and UDP all you really need is the IP address and a port to connect to. The Server Listens to connections to a port and the client make connections to a remote port.
If you really want to get way to deep into TCP and the other things related like ICMP and what not, you may want to check out "UNIX Network Programming", an excelent book on the subject. Its usually a big white book with blue letters.
That book covers pretty much everything, along with example "C" source code to see how things are handled in code.
I know its UNIX, but once you understand that, then you can tackle any SOCK interface ever made real easy.
I'm having problems with freezing when another person joins. It will freeze one computer (the joiner). I think it is because it isn't get the host player correctly.
AppTitle "Internet Game" SetBuffer BackBuffer() Print "Dial-up:" Print " Click Modem Connection for DirectPlay" Print " Wait until DirectPlay connects" Print " Then connect to or create a game" Print " -or-" Print " Use your ISPs program to connect" Print "Broadband:" Print " Click TCP/IP Connection for DirectPlay" Print " Type the host's IP address" Print " Click OK" Print " The join or create a game" Print "LAN/Network:" Print " Click OK" Print " Then join or create the game" Print "Serial Connection (direct) - Not Reccomended:" Print " Select the COM port" Print " Set any other settings" Print " Click OK" Print " Then Join or connect to the game" ;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;Types;;;;;;;; ;;;;;;;;;;;;;;;;;;;;; Type EnemyType Field Name$ Field mesh Field Id Field Team End Type Type BulletType Field mesh End Type SeedRnd MilliSecs() Global Game = StartNetGame() If Game = 0 Then End EndIf If Game = 1 Then DebugLog "Joined the Game" Else DebugLog "Hosted the Game" EndIf Graphics3D 1024,768,32,1 DebugLog "Graphics: " + GraphicsWidth() + "x" + GraphicsHeight() + "x" + GraphicsDepth() Global Name$ = Input$("Enter Your Name: ") DebugLog "Name: " + Name$ Print "Teams" Print "1. Blue" Print "2. Red" Print Global Team = Input("") DebugLog "Team: " + Team ;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;Arrays;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;; Dim sight(2) Dim boxes(5,2) ;Load Required Data Global BulletMesh = LoadMesh("Bullet.3ds") Global GunFire = LoadSound("gunfire.wav") Global Hum = LoadSound("hum.wav") sight(0) = LoadImage("Sight.bmp") Building = LoadMesh("Building2-7.b3d") Sub = LoadMesh("Submarine.b3d") Global enemy = LoadMesh("Person.3ds") SoundVolume Hum,2 LoopSound Hum If BulletMesh = 0 Then RuntimeError "Bullet.3ds Not Found" If GunFire = 0 Then RuntimeError "gunfire.wav Not Found" If sight(0) = 0 Then RuntimeError "Sight.bmp Not Found" ;Clear all button history FlushKeys() FlushMouse() FlushJoy() Global id = CreateNetPlayer(Name$) DebugLog "ID: " + id SendNetMsg(1,Name$ + "," + Team,id) DebugLog "Sent join Data" If Game = 1 Then ;If game was joined SendNetMsg(4,"Host Player",id) DebugLog "Sent Request for Host" loop = 0 While loop = 0 If NetMsgType() = 5 And RecvNetMsg() Then thisEnemy.EnemyType = New EnemyType DebugLog "Host Type Created" start = Instr(NetMsgData$(),",") thisEnemy\Name$ = Left(NetMsgData$(),start - 1) DebugLog "Host Name: " + thisEnemy\Name$ thisEnemy\Team = Mid$(NetMsgData$(),start + 1,Len(NetMsgData$())) DebugLog "Host Team: " + thisEnemy\Team ;thisEnemy\Name$ = Mid$(NetMsgData$(),7,Len(NetMsgData$())) thisEnemy\Id = NetMsgFrom() DebugLog "Host Id: " + NetMsgFrom() thisEnemy\mesh = CopyMesh(enemy) loop = 1 Goto EndHostGetLoop EndIf Wend .EndHostGetLoop SendNetMsg(4,"Box",id) DebugLog "Sent Request for Boxes" For i = 0 To 4 RecvNetMsg() If NetMsgType() = 5 Then start = Instr(NetMsgData$(),",") x = Left(NetMsgData$(),start - 1) start2 = Instr(NetMsgData$(),"|") y = Mid(NetMsgData$(),start + 1,start2 - 1) z = Right(NetMsgData$(),Len(NetMsgData$()) - start2) PositionEntity boxes(i,0),x,y,z i = i + 1 EndIf Next EndIf Cls HideEntity BulletMesh sight(1) = 0 MidHandle sight(0) ;RotateEntity Building,Rand(0,360),Rand(0,360),Rand(0,360) HideEntity enemy EntityType enemy,3 EntityType bulletMesh,4 If Building = 0 Then RuntimeError "File: 'Building.b3d' Not Found" EndIf Collisions 1,2,2,2 Global players For i = 0 To 4 boxes(i,0) = CreateCube() ResizeMesh(boxes(i,0),1,1,1) Randomize(boxes(i,0)) Next Global SubPiv = CreatePivot() PositionEntity SubPiv,38.5,-5,15.5 Global SubPiv2 = CreatePivot() PositionEntity SubPiv2,43.5,-5,15.5 Global player = CreatePivot() If player = 0 Then RuntimeError "Failed to create the player pivot" PositionEntity player,0,1,0 EntityRadius player,.3 EntityType player,1 Global box = CreateCube() ResizeMesh(box,1,1,1) HideEntity box Global camera = CreateCamera(player) If camera = 0 Then RuntimeError "Failed to create camera" CameraRange camera,.1,200 Global Mike = CreateListener(camera) Global light = CreateLight() If light = 0 Then RuntimeError "Failed to create light" LightColor light,32,32,32 TurnEntity light,45,-45,0 EntityFX Building,1 EntityFX Sub,1 EntityType Building,2 EntityType Sub,2 PositionEntity Sub,100,0,0 sp#=.05 ey#=EntityY(player) If Team = 1 Then PositionEntity player,21.5,2,43.5 ElseIf Team = 2 Then PositionEntity player,30.5,-4,-20.5 EndIf While Not KeyHit(1) yv#=EntityY(player)-ey ey=EntityY(player) If KeyHit(57) yv=.1 MoveEntity player,0,yv-.005,0 If KeyHit(31) sight(1) = Not sight(1) If KeyDown(30) TurnEntity camera,-2,0,0 If KeyDown(44) TurnEntity camera,+2,0,0 If KeyDown(203) TurnEntity player,0,2,0 If KeyDown(205) TurnEntity player,0,-2,0 If MouseDown(1) And sight(1) thisbullet.BulletType = New BulletType thisbullet\mesh = CopyMesh(bulletMesh) RotateEntity thisBullet\mesh,EntityPitch(player,1),EntityYaw(player,1),EntityRoll(player,1) PlaySound GunFire PositionEntity thisBullet\Mesh,EntityX(player),EntityY(player),EntityZ(player) EntityType thisbullet\Mesh,3 EndIf If KeyDown(200) MoveEntity player,0,0,sp If KeyDown(208) MoveEntity player,0,0,-sp Distance = EntityDistance(player,box) EmitSound(Hum,SubPiv) EmitSound(Hum,SubPiv2) For biter.BulletType = Each BulletType MoveEntity biter\mesh,0,0,1 If Abs(EntityX(biter\mesh,1)) > 1000 FreeEntity biter\mesh Delete biter ElseIf Abs(EntityY(biter\mesh,1)) > 1000 FreeEntity biter\mesh Delete biter ElseIf Abs(EntityZ(biter\mesh,1)) > 1000 FreeEntity biter\mesh Delete biter EndIf Next If frame = 25 Then SendNetMsg 2,EntityX(player) + "," + EntityY(player) + "|" + EntityZ(player),id frame = 0 EndIf frame = frame + 1 RecvNetMsg() If NetMsgType() = 2 Then start = Instr(NetMsgData$(),",") x = Left(NetMsgData$(),start - 1) start2 = Instr(NetMsgData$(),"|") y = Mid(NetMsgData$(),start + 1,start2 - 1) z = Right(NetMsgData$(),Len(NetMsgData$()) - start2) For thisEnemy.EnemyType = Each EnemyType If thisEnemy\Id = NetMsgFrom() Then PositionEntity thisEnemy\mesh,x,y,z LabelEntity(camera,thisEnemy\mesh,thisEnemy\Name$) EndIf Next EndIf TurnEntity player,0,-MouseXSpeed(),0 CheckMail() If KeyDown(54) Then sp# = 2 ElseIf KeyDown(42) Then sp# = .2 Else sp# = .05 EndIf If KeyDown(17) Then WireFrame True Else WireFrame False EndIf If NetMsgType() = 1 players = players + 1 thisEnemy.EnemyType = New EnemyType thisEnemy\mesh = CopyMesh(enemy) thisEnemy\Name$ = Left$(NetMsgData$(),Instr(NetMsgData$(),",") - 1) thisEnemy\Team = Mid$(NetMsgData$(),Instr(NetMsgData$(),",") + 1,Len(NetMsgData$())) thisEnemy\Id = NetMsgFrom() Print "Team: " + thisEnemy\Team Delay 1000 EndIf If NetMsgType() = 98 Then Print NetMsgData$() + " has quit the game" For thisEnemy.EnemyType = Each EnemyType If thisEnemy\Id = NetMsgFrom() Then FreeEntity thisEnemy\mesh Delete thisEnemy EndIf Next EndIf If NetMsgType() = 4 And NetMsgData$() = "Host Player" Then SendNetMsg(5,Name$ + "," + Team,id,NetMsgFrom()) EndIf If Game = 2 And NetMsgType() = 4 And NetMsgData$() = "Get" Then SendNetMsg(4,"Send: " + Players,NetMsgFrom()) EndIf If NetMsgType() = 99 Then Cls Locate 0,0 EndGraphics Print "You lost. " + NetMsgData() + " Won!" Delay 500 EndGame() EndIf For i = 0 To 4 If EntityDistance(player,boxes(i,0)) < 1 And boxes(i,1) <> Team Then ;FreeEntity boxes(i,0) If Team = 1 Then PositionEntity boxes(i,0),21.5,2,43.5 ElseIf Team = 2 Then PositionEntity boxes(i,0),30.5,-4,-20.5 EndIf boxes(i,1) = Team Print "You found a box" Delay 500 EndIf Next UpdateWorld RenderWorld If sight(1) = 1 Then DrawImage sight(0),GraphicsWidth() / 2,GraphicsHeight() / 2,0 EndIf For thisEnemy.EnemyType = Each EnemyType LabelEntity(camera,thisEnemy\mesh,thisEnemy\Name$) Next Flip ;Print Infomation Locate 0,0 Print "Frame: " + frame Print "Triangles Rendered: " + TrisRendered() Print "X: " + EntityX(player) Print "Y: " + EntityY(player) Print "Z: " + EntityZ(player) Wend SendNetMsg 98,Name$,id EndGame() End Function ResizeMesh(mesh,width#,height#,depth#) ScaleMesh mesh,1/MeshWidth#(mesh)*width#,1/MeshHeight#(mesh)*height#,(1/MeshDepth#(mesh))*depth# End Function Function EndGame() FreeEntity Building FreeImage sight(0) DeleteNetPlayer id EndGraphics End End Function Function CheckMail() If NetMsgType() = 4 And NetMsgData$() = "Box" Then For i = 0 To 4 SendNetMsg(5,EntityX(Boxes(i,0)) + "," + EntityY(Boxes(i,0)) + "|" + EntityZ(Boxes(i,0)),id) Next EndIf If NetMsgType() = 97 Then If NetMsgData = Name$ Then PositionEntity player,0,1,0 EndIf EndIf If NetMsgType() = 5 Then Repeat RecvNetMsg() If NetMsgType() = 5 Then start = Instr(NetMsgData$(),",") x = Left(NetMsgData$(),start - 1) start2 = Instr(NetMsgData$(),"|") y = Mid(NetMsgData$(),start + 1,start2 - 1) z = Right(NetMsgData$(),Len(NetMsgData$()) - start2) PositionEntity boxes(i,0),x,y,z i = i + 1 EndIf Until i = 4 EndIf If NetMsgType() = 200 Then Locate 0,0 DeleteNetPlayer id RuntimeError "A Fatal Error Occurred" EndGame() EndIf End Function Function Randomize(boxmesh) Select Rand(0,6) + 1 Case 1 PositionEntity boxmesh,-7,0,-7 Case 2 PositionEntity boxmesh,19,0,-18 Case 3 PositionEntity boxmesh,18,4,-18 Case 4 PositionEntity boxmesh,25,-3,-10 Case 5 PositionEntity boxmesh,5,-2,22 Case 6 PositionEntity boxmesh,Rand(-8,30),0,Rand(-22,26) Case 7 PositionEntity boxmesh,27,6,3 End Select End Function Function LabelEntity (camera, entity, label$) If EntityInView (entity, camera) CameraProject camera, EntityX (entity), EntityY (entity), EntityZ (entity) w = StringWidth (label$) h = StringHeight (label$) x = ProjectedX () - (w / 2) - 1 y = ProjectedY () - (h / 2) - 1 Color 0, 0, 0 Rect x, y, w + 2, h + 2, 1 Color 255, 255, 255 Text x, y, label$ EndIf End Function Function WaitNetMsg() Repeat Until RecvNetMsg() End Function ;Msg Types ;1 = Join ;2 = Position ;3 = Mail (Send a msg) ;4 = Request ;97 = Reset Player ;98 = Quit ;99 = Win/Lose