Something that should added to this discussion is that you should also think about it kind of the same way you, for example, load a save game, or even structure a program. How does the program know you are entering a login and password? Oh, you are on the login and password screen. Of course. How does my game know I'm ready to load the save file? Ah, I have to tell it. That may seem overly vague but the point is the server should be listening and the conversation goes a bit like:
Code:
SERVER: Ding! Oh, I have a message. IP wants to log on.
SERVER: <sends request to IP for username and password>
SERVER: <is waiting for reply from IP>
IP: Here is my username and password.
IP: <sends username>
SERVER: <receives username>
SERVER: <sends response, I got the username, send password>
IP: <receives response>
IP: <sends password>
SERVER: <receives password>
SERVER: Hmm, these look good, I'll let you in.
SERVER: <adds IP to list of accepted clients>
SERVER: <sends response, you are now connected>
IP: <receives response>
Now maybe that sounds a little dumb, but a networking action isn't really so different from two people or more people talking. It's just that the conversation they have is a little strange. If you just pick up the phone and yell a username and password into it, probably not going to get a lot done. Consider banking: you have to call, let them know what you are trying to do, they'll ask you for some details to validate who you are, and then you can proceed. The important things there is that when they ask me for, say, my date of birth if I give them my social security number it's not going to work well. In the case of the login process, the server should be
expecting the username from the client because it asked for it. And the client should know to send it because the server told it to. Now, granted, you can roll some of this stuff up, such as perhaps the initial request to log in includes the username, the server can say, okay what's your password. Or maybe you send both, but you still need to tell the server: "Hey, I'm trying to log in." Otherwise even if you tell it: "This data is a password." It's left going, "Yeah, and what do you want me to do with it?"