Author |
Message |
Tweety
Boo! inc.
Joined: Fri Jan 04, 2002 3:00 am Posts: 221 Location: Canada
|
packets
i've been playing around with socket connections and found that often the text from trade wars is broken up quite a lot. You may have half a persons name in one packet, and then the next is the rest. or at least that is how it seems. sometimes you will get it all in one.
with prompts, you get no line return, so you can't really read up until a line return because you will miss the prompt. so i thought, well i could buffer it up. and then read from the buffer to match text. but what i'm thinking is that i need a way to know when thats all thats coming. and if i can't rely on a line return to mark the end, how do i know what is actually the end?
so i thought. well buffer it, then read. if a match take that part out of the buffer and continue from where i was matching the next. but what if the packets come in a different order? i'd have some crap in the buffer that never makes it out lol.
would i end up with mis matched packets? i don't think there is a real order. they are just sent and when they arrive they arrive. I think that is how it works in tcp.
what have people found that helps things out?
|
Tue Nov 12, 2013 2:00 am |
|
|
Mongoose
Commander
Joined: Mon Oct 29, 2001 3:00 am Posts: 1096 Location: Tucson, AZ
|
Re: packets
I struggled with this in Weapon M. There seems to be no rhyme or reason to where the game splits text into packets. And I think they could be split up further in transmission. There are a couple situations where not knowing what's coming leads to ambiguity about the meaning of what's already been received, but off the top of my head I can't remember what they are. I ended up having a flag in the parser that indicates when it's "at" a prompt. When the complete text of a prompt is received, it fires a prompt event and sets the flag true. When any additional text is received, the flag is cleared. This could be the echo of a command typed at the prompt, or a newline or clear line command preceding some other message. Then another prompt will be displayed. Tweety wrote: what if the packets come in a different order? That's something you don't need to worry about. TCP reassembles the packets and presents them to the application layer in the order they were sent.
_________________ Suddenly you're Busted!
|
Tue Nov 12, 2013 12:56 pm |
|
|
Micro
Ambassador
Joined: Wed Apr 20, 2011 1:19 pm Posts: 2559 Location: Oklahoma City, OK 73170 US
|
Re: packets
You just have to store the partial lines, and wait for the next packet. If you received a partial line (no <CR>), you can go ahead and process the line if the connection is idle for about 100ms. You might also note that TradeWars sends the <CR><LF> in the wrong order.
_________________ Regards, Micro Website: http://www.microblaster.net TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002
ICQ is Dead Jim! Join us on Discord: https://discord.gg/zvEbArscMN
|
Sun Nov 17, 2013 4:20 pm |
|
|
Mongoose
Commander
Joined: Mon Oct 29, 2001 3:00 am Posts: 1096 Location: Tucson, AZ
|
Re: packets
It's even worse than that. The backwards LF + CR newlines show up outside the game, in TWGS menus. Inside the game, you get CR + ESC[0; + LF!
My solution was to handle CR and LF separately. CR returns the cursor to column 0 (or column 1 in VT/ANSI's 1-based counting) and LF moves it to the next line. Then it doesn't matter which order they show up in.
_________________ Suddenly you're Busted!
|
Mon Nov 18, 2013 4:32 pm |
|
|
Micro
Ambassador
Joined: Wed Apr 20, 2011 1:19 pm Posts: 2559 Location: Oklahoma City, OK 73170 US
|
Re: packets
Mongoose wrote: It's even worse than that. The backwards LF + CR newlines show up outside the game, in TWGS menus. Inside the game, you get CR + ESC[0; + LF!
My solution was to handle CR and LF separately. CR returns the cursor to column 0 (or column 1 in VT/ANSI's 1-based counting) and LF moves it to the next line. Then it doesn't matter which order they show up in. I think that explains some rendering glitches I have been seeing. I was ignoring LF and doing a CR/LF for every CR, but I like your solution better. Do you still consider the CR the end of the line for lexical parsing?
_________________ Regards, Micro Website: http://www.microblaster.net TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002
ICQ is Dead Jim! Join us on Discord: https://discord.gg/zvEbArscMN
|
Tue Nov 19, 2013 3:35 pm |
|
|
Mongoose
Commander
Joined: Mon Oct 29, 2001 3:00 am Posts: 1096 Location: Tucson, AZ
|
Re: packets
I have the text stream going to two independent parsers: the data parser and the terminal parser. The terminal parser treats CRs and LFs separately as I described before. With few exceptions, the data parser doesn't care about newlines at all. Most of the patterns it's looking for are on a single line, and end when something that isn't part of the pattern shows up. Whether that's a newline or something else, it just ignores it.
_________________ Suddenly you're Busted!
|
Tue Nov 19, 2013 6:45 pm |
|
|
Tweety
Boo! inc.
Joined: Fri Jan 04, 2002 3:00 am Posts: 221 Location: Canada
|
Re: packets
yeah, i'm leaning towards firing off events on matching text. I haven't worked on it for a bit though.
|
Tue Nov 19, 2013 10:44 pm |
|
|
Micro
Ambassador
Joined: Wed Apr 20, 2011 1:19 pm Posts: 2559 Location: Oklahoma City, OK 73170 US
|
Re: packets
What language are you using?
_________________ Regards, Micro Website: http://www.microblaster.net TWGS2.20b/TW3.34: telnet://twgs.microblaster.net:2002
ICQ is Dead Jim! Join us on Discord: https://discord.gg/zvEbArscMN
|
Tue Nov 19, 2013 10:48 pm |
|
|
Tweety
Boo! inc.
Joined: Fri Jan 04, 2002 3:00 am Posts: 221 Location: Canada
|
Re: packets
I'm using objective-c. So far I have a basic proxy server. just working on how to do some data parsing. then i'll look into building a interpreter of some sort to read .ts twx proxy files. and maybe then look at working with compiled versions. right now I have my mac app in the status bar kind of like twx proxy does in the status bar. with a menu system. its a hobby project
|
Tue Nov 19, 2013 10:53 pm |
|
|
Kaus
Gameop
Joined: Tue Nov 19, 2002 3:00 am Posts: 1050 Location: USA
|
Re: packets
Tweety which framework are you using in Objective -C, call me curious.
_________________ Dark Dominion TWGS Telnet://twgs.darkworlds.org:23 ICQ#31380757, -=English 101 pwns me=- "This one claims to have been playing since 1993 and didn't know upgrading a port would raise his alignment."
|
Fri Nov 22, 2013 5:21 pm |
|
|
Tweety
Boo! inc.
Joined: Fri Jan 04, 2002 3:00 am Posts: 221 Location: Canada
|
Re: packets
It is a Cocoa app
|
Fri Nov 22, 2013 6:30 pm |
|
|
Mongoose
Commander
Joined: Mon Oct 29, 2001 3:00 am Posts: 1096 Location: Tucson, AZ
|
Re: packets
I saw some Objective-C code once. Scarred me for life.
_________________ Suddenly you're Busted!
|
Fri Nov 22, 2013 8:00 pm |
|
|
Tweety
Boo! inc.
Joined: Fri Jan 04, 2002 3:00 am Posts: 221 Location: Canada
|
Re: packets
it is definitely a change from other languages i've learnt. naming conventions and some syntax.
lots of [[brackets alloc] init];
lol
|
Sat Nov 23, 2013 2:17 am |
|
|
|