| View previous topic :: View next topic |
| Author |
Message |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Sat Mar 08, 2008 3:24 am Post subject: Using TCP and UDP at Once |
|
|
Is it a good idea to use TCP and UDP in the same application. For example, think of an online deathmatch game. UDP could be used to update positions and animation states while TCP could send crucial data such as scoring and other stuff.
If I send UDP messages every frame, and a packet gets lost along the way, would that packet be gone for good, or is there a possibility that it will show up later on after fresh data has been received and processed?
Another thing, is it a good idea to send multiple messages at once to a client instead of sending all the data in one shot? For example, send all character positions in one packet and then all the weapon existence states on the map in another. I would think sending it all at once would be a good way to go, but then again, I thought rendering a 128x128 image in one call would be much faster than rendering that same 128x128-pixel image in 64x64-pixel sections. |
|
| Back to top |
|
 |
PhonicUK
Joined: 07 Mar 2008 Posts: 3
|
Posted: Sat Mar 08, 2008 3:54 am Post subject: |
|
|
Mixing UDP and TCP is usually how its done. TCP for stuff that doesn't need to be fast and instant like login and scores, UDP for things like movement and position.
With UDP there is a risk that the packet will either be lost forever, or will show up again later than expected. So you need a means of dumping late-show packets.
Also with UDP you can't guarntee that packets will arrive in the same order they where transmitted (Part of the reason why its so fast) so its generally a good idea to make sure all of your data can fit inside 1 packet. |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Sat Mar 08, 2008 4:03 am Post subject: |
|
|
Ok, I'll use both protocols then. I have a simple TCP game setup between two PSPs right now. They are run through my 2WIRE router/access-point. Does that mean that my application will be able to run through the internet as well as long as the port I use is free?
Also, I am using one port in my TCP game. Is it good to use one port for the server PSP and have the other PSPs that act as clients use other different ports? |
|
| Back to top |
|
 |
PhonicUK
Joined: 07 Mar 2008 Posts: 3
|
Posted: Sat Mar 08, 2008 5:59 am Post subject: |
|
|
Yes as long as the port is free, your app should be able to connect to the outside world.
Stick to as few ports as you can. Makes things much eaiser in the long run. |
|
| Back to top |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Sat Mar 08, 2008 6:08 am Post subject: |
|
|
| Only difference is that you won't use the local IP (192.168.x.x or whatever) but the NAT traversed IP. |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Sat Mar 08, 2008 6:20 am Post subject: |
|
|
| So, how to do I obtain the NAT software-wise since the router will give that to me? |
|
| Back to top |
|
 |
ttotto
Joined: 26 Nov 2007 Posts: 8
|
Posted: Sat Mar 08, 2008 1:18 pm Post subject: |
|
|
I think you need to use Net Resovling.
look here for more info.
http://psp.jim.sh/pspsdk-doc/pspnet__resolver_8h.html#703d7ea8d7f5bbc9fe4330891d144884
This function:
sceNetResolverStartNtoA (int rid, const char *hostname, struct in_addr *addr, unsigned int timeout, int retry);
Can convert lets say the DNS Name is "www.google.com" it will return an IP address "74.125.19.104"
There is also an example in the SDK.
Hope That Helps! |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Mon Mar 10, 2008 3:14 am Post subject: |
|
|
| I don't have a domain name though. I need my PSP to be converted to an external IP address though, wouldn't I because that is what I am using as the game server? |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Mon Mar 10, 2008 5:14 am Post subject: |
|
|
| If you expect people outside your network to be able to connect to your PSP behind a NAT, you'll have to set up some form of forwarding on the router as well, or use one of the many forms of NAT traversal (STUN, etc). This is pretty basic networking stuff, there's nothing specific to the PSP here. |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Tue Mar 11, 2008 2:10 am Post subject: |
|
|
Does the XBOX360 and PS3 have to forward ports when they go online? I know that the XBOX360 checks the NAT when it attempts to connect to XBOX LIVE.
It won't just be my PSP people will be conecting to. The player of the game can choose to host (be the server) or join (be the client) the game. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Tue Mar 11, 2008 3:43 am Post subject: |
|
|
| Ports are forwarded by the ROUTER, not the computer/console (unless you're using a computer as a router). LinkSys puts the port forwarding settings on the Applications and Gaming tab. |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Wed Mar 12, 2008 2:53 pm Post subject: |
|
|
| So, then all I would have to do is use my external address instead of my local one when I go to bind my client socket information? |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Wed Mar 12, 2008 4:34 pm Post subject: |
|
|
| No, you'll need to understand NAT a lot better first and figure out which of many methods will suit you (static NAT, uPnP, STUN, etc) |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Wed Mar 12, 2008 11:47 pm Post subject: |
|
|
| Ok, I'll research them. How do I use them in programming in programming? Do I have to write something from scratch, or are there options with the socket library I can use to use NAT? I've been trying to figure out how to use NAT, but all I know right now is that it is something that the router does... |
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Thu Mar 13, 2008 6:23 am Post subject: |
|
|
| NAT is a networking concept. It's not something you "use" from your program. You'll need to understand that before you can figure out ways to deal with the issues it causes. |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Thu Mar 13, 2008 6:59 am Post subject: |
|
|
| Ok, I knew it was a hardware thing that the router handles from a little research, but I thought there could possibly be a way of checking it with specific functions or something like that... I don't know, but I'll look into it more. NAT sounds like an algorithm, and that there are different algorithms out there such as uPnp and STUN, or something like that... |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Thu Mar 13, 2008 12:59 pm Post subject: |
|
|
The way you forward a port is to log into the modem/router (usually something like 192.168.1.1 or 192.168.0.1), go to the page that controls the ports, and tell it which port to forward to which local IP address. Just use your favorite browser to do this.
For example, I type 192.168.1.1 into the address field of Firefox and I get the login for my LinkSys router. After entering the login name and password, I can then go to the Applications and Gaming tab where the first sub-tab is Port Range Forward. I tell it a port or range of ports, whether to forward TCP, UDP, or both, and the local IP address to forward those port(s) to. Click Save Settings at the bottom of the page and the ports are now forwarded where I want them to go. |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Thu Mar 13, 2008 1:16 pm Post subject: |
|
|
| So then I won't have to mess with NAT or anything like that? How would the people across the internet be able to access others' games they have online? Would they do it the same way they would if it was working locally, but instead using my external address? |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Fri Mar 14, 2008 3:24 am Post subject: |
|
|
| Vincent_M wrote: | | So then I won't have to mess with NAT or anything like that? How would the people across the internet be able to access others' games they have online? Would they do it the same way they would if it was working locally, but instead using my external address? |
You shouldn't need to mess with the NAT at all. I certainly haven't. Port forwarding has one main purpose - to get external packets directed to a specific port to one particular computer/console. Think about it a moment: here's my setup...
Router --- DSL
|--- Computer 1
|--- Computer 2
|--- Computer 3
|--- Computer 4
|
wifi to three PSPs
If you get the IP address for any of the computers or PSPs locally, it shows the local address. If you get the IP from something like WhatIsMyIP.com, they all show the same IP address (since they share the same connection). So how is someone in Taiwan supposed to connect to computer 4 for a Death Match? They use the single IP address my connection is assigned, and direct the packets to a specific port. I must then make sure that port is forwarded to computer 4.
If I were Death Matching between computer 2 and one of the PSPs, I would use the local IP addresses and therefore not need to forward a port since all local addresses are unique. So as I said above - port forwarding is to make sure packets not from local machines can get to the correct local machine. Packets from local machines can get to another local machine without that. |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Fri Mar 14, 2008 7:23 am Post subject: |
|
|
| Ok, so I just need to forward a port so that my PSP can contact all the other PSPs out there in the network. However, what if I had 3 PSPs running locally in the same game playing with 5 other PSPs located all over the world? Would I need to forward 3 ports: one for each PSP then? |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Fri Mar 14, 2008 12:24 pm Post subject: |
|
|
| Vincent_M wrote: | | Ok, so I just need to forward a port so that my PSP can contact all the other PSPs out there in the network. However, what if I had 3 PSPs running locally in the same game playing with 5 other PSPs located all over the world? Would I need to forward 3 ports: one for each PSP then? |
Haven't every done that myself, so I can't sure for certain. Might be that the router can handle that... might be you'll need more ports and forward them accordingly. I'd google for that iffen I were you. :)
Can't rightly say I know ANYONE who's done multiple locals vs multiple externals. It's always multiple locals, period, or one local, period. |
|
| Back to top |
|
 |
Vincent_M
Joined: 03 Apr 2007 Posts: 73
|
Posted: Fri Mar 14, 2008 3:46 pm Post subject: |
|
|
| Quote: | | Can't rightly say I know ANYONE who's done multiple locals vs multiple externals. It's always multiple locals, period, or one local, period. |
Yeah, that's how I would think anyone would do it too. After all, there's only one console hooked up to an access-point usually. I'd only want to have multiple PSPs hook up locally with multiple PSPs outside of the my network just to see how performance works between 8 PSPs. Having a good deal of them close to me would be good because I can run tests quickly without having to rely on a bunch of other people while still being able to test how interaction works with the outside world. On the plus side, I do have 3 PSPs to work with right now, and I might be able to borrow 2 so that I can have a 5-player test. :p That'd be tight! |
|
| Back to top |
|
 |
|