Using TCP and UDP at Once
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.
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.
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.
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.
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?
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?
-
- Posts: 376
- Joined: Wed May 10, 2006 11:31 pm
I think you need to use Net Resovling.
look here for more info.
http://psp.jim.sh/pspsdk-doc/pspnet__re ... 891d144884
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!
look here for more info.
http://psp.jim.sh/pspsdk-doc/pspnet__re ... 891d144884
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!
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...
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...
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.
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.
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...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?
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.
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. :)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?
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!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.