|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Merging data received via TCPI'm having a weird problem... Part of code first: Dim bytes(tcpClient.ReceiveBufferSize) As Byte Dim DataChunk as String Dim FullData as String Do While EOF = False If networkStream.DataAvailable = True Then networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) DataChunk = Encoding.ASCII.GetString(bytes) DataChunk = Trim(DataChunk) FullData = FullData & DataChunk bytes.Clear(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) If DataChunk="EOF,AppConfirmationString" EOF = True End If End If Loop When a number of packets is received on the socket (e.g. client sending data line by line rather than a single stream), FullData always equals to whatever the first packet (line) included. It just doesn't seem to add DataChunk to itself each time loop is run. Why? When instead of this I try adding DataChunk to a textbox, it's fine, at the end I have all data sent to me in textbox... -- Greets, Arkadiusz 'Winger' Slusarczyk Republic of Ireland Winger wrote:
Show quoteHide quote > Hi, I am wondering if your code is contained within an Event?? If so, you > > I'm having a weird problem... Part of code first: > > Dim bytes(tcpClient.ReceiveBufferSize) As Byte > Dim DataChunk as String > Dim FullData as String > > Do While EOF = False > If networkStream.DataAvailable = True Then > networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) > DataChunk = Encoding.ASCII.GetString(bytes) > DataChunk = Trim(DataChunk) > FullData = FullData & DataChunk > bytes.Clear(bytes, 0, CInt(tcpClient.ReceiveBufferSize)) > If DataChunk="EOF,AppConfirmationString" > EOF = True > End If > End If > Loop > > When a number of packets is received on the socket (e.g. client sending > data line by line rather than a single stream), FullData always equals > to whatever the first packet (line) included. It just doesn't seem to > add DataChunk to itself each time loop is run. Why? > When instead of this I try adding DataChunk to a textbox, it's fine, at > the end I have all data sent to me in textbox... > may be looking at a re-entrant issue which could cause the problem you're describing. (Try temporarily defining "FullData" globally, that would expose this). Otherwise, try putting a Counter within your main Loop with output going to the Immediate Window, or using Debug.Print(DataChunk) after each "DataChunk = Trim(DataChunk)" line. This will show you what is being read into that Variable. ShaneO There are 10 kinds of people - Those who understand Binary and those who don't. Hi,
ShaneO wrote: > I am wondering if your code is contained within an Event?? If so, you It's part of a function launched when there is connection pending on TCP > may be looking at a re-entrant issue which could cause the problem > you're describing. (Try temporarily defining "FullData" globally, that > would expose this). port. > Otherwise, try putting a Counter within your main Loop with output going I have debugged line that is supposed to append DataChunk to Fulldata a > to the Immediate Window, or using Debug.Print(DataChunk) after each > "DataChunk = Trim(DataChunk)" line. This will show you what is being > read into that Variable. number of times and result was: - when line was about to be executed, it showed me these values: FullData = FullData & DataChunk "String1" "String1" "String 2" After the line was executed, FullData was still... "String 1". This is really weird for me. Working in VS .Net 2003 by the way. -- Greets, Arkadiusz 'Winger' Slusarczyk Republic of Ireland Winger wrote:
Show quoteHide quote > Hi, All of the above would still indicate to me that you are indeed looking > > ShaneO wrote: > >> I am wondering if your code is contained within an Event?? If so, you >> may be looking at a re-entrant issue which could cause the problem >> you're describing. (Try temporarily defining "FullData" globally, >> that would expose this). > > > It's part of a function launched when there is connection pending on TCP > port. > >> Otherwise, try putting a Counter within your main Loop with output >> going to the Immediate Window, or using Debug.Print(DataChunk) after >> each "DataChunk = Trim(DataChunk)" line. This will show you what is >> being read into that Variable. > > > I have debugged line that is supposed to append DataChunk to Fulldata a > number of times and result was: > - when line was about to be executed, it showed me these values: > FullData = FullData & DataChunk > "String1" "String1" "String 2" > After the line was executed, FullData was still... "String 1". This is > really weird for me. > Working in VS .Net 2003 by the way. > at a re-entrant issue. It would appear your "Function" is being simultaneously executed more than once. Did you try globally declaring "FullData"? You will need to remove (or REM) your "Dim FullData as String" line and declare it in the General Declarations section at the top of your program. I'd be interested to know the results. ShaneO There are 10 kinds of people - Those who understand Binary and those who don't. ShaneO wrote:
> All of the above would still indicate to me that you are indeed looking I use threading (ThreadPool) to launch new thread that handles incoming > at a re-entrant issue. It would appear your "Function" is being > simultaneously executed more than once. TCP connection. This way application can process data without blocking listening port and I'm ready for next connection... Yet, all tests were done with a single connection only, straight after program was started, so new thread was created only once... > Did you try globally declaring "FullData"? You will need to remove (or I've tried that, result was identical...> REM) your "Dim FullData as String" line and declare it in the General > Declarations section at the top of your program. I will be rewriting full code anyway (have few reasons for that), I will see wheter problem will still occur... -- Greets, Arkadiusz 'Winger' Slusarczyk Republic of Ireland
How to extract multiple occurrences of a substring
Best Practices Replacement code for Threading.Thread.Sleep Enumerating MDIList Menu Item at Run-Time Regex.Replace Textbox data entry validation SQL Server reporting services... Wait while processing dialog boxes (threading?) COM usage problem? Publishing with ClickOnce |
|||||||||||||||||||||||