Post

 Resources 

Console


Re: How to pass multiplayer data though winsock? Mattman (8 replies, 0 views) (2001-Jun-27)
-
ok, you have the sending pretty much correct...you use a delimeter (in this case you're using Chr$(127)...though I prefer Chr$(0)). However, you do not want to use the Split routine to break apart the data. Let's say you send the following data: "Mattman: Hey, guys!" & Chr$(127) & "YellowSheep: What's up??" Now the way you're currently receiving data is that you're expecting that you're expecting it to arrive all at once, just as you sent it. If that were true, I could combine 25 megs worth of characters, send it, and expect it all to arrive at once, which as we all know doesn't happen...yet. ;) Here are some possible ways the data will be received: 1. "Mattman: Hey, guys!" & Chr$(127) & "YellowSheep: What's up??" 2. A chunk of "Mattman: Hey, g", followed by a chunk of "uys!" & Chr$(127) & "YellowSheep: What's up?" 3. A chunk of "Mattman: Hey, guys!" & Chr$(127) & "Ye", followed by a chunk of "llowShee", followed by a chunk of "p: What's up??" Unfortunately, splitting the data with the Split command is impractical, as it may not all have arrived yet. (Data can also be chunked together when you don't want it to, so watch for that too.) Here's a sample of how to handle the incoming data instead: <PRE> ' ---------------------------------------------------- ' This must be either a PUBLICLY or STATICALLY declared string!!! Public sCurrentData As String ' Or Static sCurrentData As String ' ---------------------------------------------------- ' This code must go within the DataArrival routine. Dim sNewData As String Dim sSplitData As String Dim nDelimeter As Long ' Get the new data. sckWinsock.GetData sNewData, vbString sCurrentData = sCurrentData & sNewData ' Locate the first delimeter mark. nDelimeter = InStr(sCurrentData, Chr$(127)) ' Loop while there is a delimeter. While nDelimeter <> 0 ' Parse the code while there is a Chr$(127) delimeter mark. sSplitData = Left$(sCurrentData, nDelimeter - 1 ' Remove the portion of the string that we parsed. sCurrentData = Right$(sCurrentData, Len(sCurrentData) - nDelimeter) ' Used the parsed segment in some function. Call Some_Function_That_Uses(sSplitData) ' Find the next location of Chr$(127), the delimeter nDelimeter = InStr(sCurrentData, Chr$(127)) Wend ' ---------------------------------------------------- </PRE> Note that I haven't tried this code, and I just wrote it from previous experiences. I have tried to optimise it for as much speed as possible, as VB is not the fastest when it comes to strings. Good luck!


-
Up One Level | Back to Forum

I dont want to use split, i want to use arrys like YellowSheep (7 replies) (2001-Jun-28)
Now it looks like you're writing to a file... Mattman (6 replies) (2001-Jun-28)
Hm ok ill explain! YellowSheep (5 replies) (2001-Jun-28)
Maybe W-Buffer (1 reply) (2001-Jun-28)
wont work for me... YellowSheep (0 replies) (2001-Jun-29)
Doesn't use Split... Mattman (2 replies) (2001-Jun-29)
hm got an idea why.../solution?! YellowSheep (1 reply) (2001-Jun-29)
Ummmm W-Buffer (0 replies) (2001-Jul-5)

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.
There have been 187 visitors within the last 20 minutes
RSS News Feed