Sign in to follow this  
Jovan

General networking question...

Recommended Posts

I went over the FAQ but to no avail. I am new to networking, but not to overall programming. My question is rather simple: Do these methods of networking (Winsock, TCP and UDP) simply "open" a connection for you and leave you to find the most efficient way to send and retrieve data (taking into account the difference between TCP and UDP); or do they do much more? In other words, do network game programmers simply pick the most effective one for the job, and start figuring out efficient methods of sending/getting packets?

Share this post


Link to post
Share on other sites
Do these methods of networking (Winsock, TCP and UDP) simply "open" a connection for you and leave you to find the most efficient way to send and retrieve data (taking into account the difference between TCP and UDP); or do they do much more?

Usually you open a socket. A socket is basically a message tube.
Since the tube is basically like a file descriptor (you write to it a message "hello kitty"), how the message is transported is usually abstracted away by the socket type. A winsock is a TCP socket. You normally say "I opened a TCP socket or I opened a UDP socket". You dont really have to worry about literally splitting the message up and reassembling it, you just have to understand that it WILL all arrive if you're using TCP or it might not all arrive if it's UDP. How long it takes, etc, is up to you to measure. Contrary to popular opinion (on any number of message boards), sockets havent ALWAYS been bidirectional, but they almost all are now.
Serverside, you get something like this:

1. Main Thread
2. Listener Thread - Spawn a process/thread with a listening socket which is a looping/blocked process waiting for a connection.
When you get a connection, spawn a new thread for handling the connection...go back to listening.
3. Connection Handler Thread - Spawn a new reader thread
4. Connection Reader Thread - New thread for reading, old thread for writing.

This is at least the way that most high end commercial programs do it, I'm pretty sure. Takes a lot of thread handling and accounting. You can read/write to a bidriectional socket at the same time...although messages are usually buffered. If I write "hello kitty" then I write "testing123" to a socket, the client on the other end will not see "testing123" until it has read "hello kitty" then has gone to read another message. In Java there's an unbuffered socket, so if you read from the socket after "testing123" all you will read out is the "testing123" not "hello kitty"....that message was lost. Messages, much like files typically have a delimiter that keeps reads and writes on both sides, atomic. I read from socketA, I get an entire message "hello kitty". Some languages like C++/Java you can make the read/write methods per byte or however you like so you'll just ready "hello kit" if you set the reading threshold low. ANYWAYS, that's a crash course in high-level programming networking today.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this