Networking

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Networking

Post by dandymcgee »

I'm currently the network guy for my software engineering project, and while it's coming along I'm curious as to what approaches others have taken regarding the common networking issues.

For example, say the user logs in via the lobby on the client side of things.
  • The user enters a user name and a password.
    The client sends it to the server.
    The server checks it against the database.
    The servers replies to the client.
    The client either grants or denies the user access.
In practice my implementation goes something like (Server Debug Output):

Code: Select all

Received FROM [127.0.0.1]: !AUTH:user,pass;
(depending on whether not it authenticated)
Sent TO [127.0.0.1]: @AUTH:Successful Login!
OR
Sent TO [127.0.0.1]: @AUTH:Invalid username or password.
All incoming data from the server is stored in a giant string on the client side.
In order to check if the log in was successful we're pausing execution (*gasp*) for ~20 ms (local network lag) then searching the string for either "Success" or "Invalid".

One major flaw (of many) with this is the string's contents as a whole persist, so once a log in is successful all future log-ins will be successful regardless.

How do you orchestrate packets so that you know what the exact reply to a specific request is (for instance, a dynamic array of strings is one way that might work for my exact situation)?

We're not lectured at all in class, it's more of a "here's what the end goal, have at it" approach which I like a lot. It just feels like sometimes I'm doing everything in a really horrible way or even just reinventing the wheel (which is usually a valuable experience anyways).
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Networking

Post by K-Bal »

Put an ID at the beginning of your message which distinguishs between the different types of messages.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Networking

Post by dandymcgee »

K-Bal wrote:Put an ID at the beginning of your message which distinguishs between the different types of messages.
That's what I'm currently doing... I asked about how to distinguish between different messages of the same type.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Live-Dimension
Chaos Rift Junior
Chaos Rift Junior
Posts: 345
Joined: Tue Jan 12, 2010 7:23 pm
Favorite Gaming Platforms: PC - Windows 7
Programming Language of Choice: c++;haxe
Contact:

Re: Networking

Post by Live-Dimension »

I don't know if this is the 'right' way but i'd probably have some sort of array system that caches each message that comes in, upon which xyz entity can scan and find out any information it needs. Atleast that's the way I'd do it in my head, but there's likely to be a better way.
Image
User avatar
EccentricDuck
Chaos Rift Junior
Chaos Rift Junior
Posts: 305
Joined: Sun Feb 21, 2010 11:18 pm
Current Project: Isometric "2.5D" Airship Game
Favorite Gaming Platforms: PS2, SNES, GBA, PC
Programming Language of Choice: C#, Python, JScript
Location: Edmonton, Alberta

Re: Networking

Post by EccentricDuck »

Wouldn't it be possible to access and void the contents of the string upon a new login attempt? Not sure if I'm approaching this from the right angle, but that would seem like the simplest way. After all, the user/progam doesn't need to access the previous log on each subsequent login, or if it does you can create a backup in a separate file. That way you're not amassing a single huge log as time goes on, and you'll only have the results of one login attempt each time the user attempts to login.
K-Bal
ES Beta Backer
ES Beta Backer
Posts: 701
Joined: Sun Mar 15, 2009 3:21 pm
Location: Germany, Aachen
Contact:

Re: Networking

Post by K-Bal »

Well, then you are not specific enough. Define an ID for "LoginSuccess" and one for "LoginFail". I don't see why you need to send whole strings for that.
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: Networking

Post by MrDeathNote »

I agree with k-bal, I use an enum with the options for sending and recieving defined eg playerMoved = 0, playerLogin = 1, playerDiconnected = 2 etc. Then write one byte at the start of the stream your sending with a value from the enum. When the server/client reads the byte they can then identify what the message is by comparing the byte to the enum value so the server/client knows how to process the data.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Networking

Post by dandymcgee »

[thinking out loud]
Alright, thanks for the suggestions guys. It's functional at the moment, but I guess I don't really know how to word what I'm trying to ask since I'm not sure exactly what I'm looking for.

I'll post again later if we encounter any errors. At this point it's probably going to wind up being somewhat of a hack that works.

What I'm getting at is regardless of whether my ID is a string, an int, a char, or whatever I was trying to distinguish between replies.

If I used a dynamic array I would probably search it backward (starting at the most recent addition) looking for the most recent AUTH reply and see whether or not it was successful. That still leaves the problem of lag, if we search too soon (before the new reply is received and added) we could find a denied AUTH request from a previous attempt and deny access for no reason. Maybe we could discard them as they've been accounted for.
[/thinking out loud]


Do you ever feel like you just need to try to explain something to someone else in order to figure out how it's going to work? I think I'm all set now. ;)
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
XianForce
Chaos Rift Devotee
Chaos Rift Devotee
Posts: 767
Joined: Wed Oct 29, 2008 8:36 pm

Re: Networking

Post by XianForce »

dandymcgee wrote: Do you ever feel like you just need to try to explain something to someone else in order to figure out how it's going to work? I think I'm all set now. ;)
I feel that way ALL the time!
Post Reply