473,614 Members | 2,328 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Merging data received via TCP

Hi,

I'm having a weird problem... Part of code first:

Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
Dim DataChunk as String
Dim FullData as String

Do While EOF = False
If networkStream.D ataAvailable = True Then
networkStream.R ead(bytes, 0, CInt(tcpClient. ReceiveBufferSi ze))
DataChunk = Encoding.ASCII. GetString(bytes )
DataChunk = Trim(DataChunk)
FullData = FullData & DataChunk
bytes.Clear(byt es, 0, CInt(tcpClient. ReceiveBufferSi ze))
If DataChunk="EOF, AppConfirmation String"
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
Apr 20 '06 #1
4 1472
Winger wrote:
Hi,

I'm having a weird problem... Part of code first:

Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
Dim DataChunk as String
Dim FullData as String

Do While EOF = False
If networkStream.D ataAvailable = True Then
networkStream.R ead(bytes, 0, CInt(tcpClient. ReceiveBufferSi ze))
DataChunk = Encoding.ASCII. GetString(bytes )
DataChunk = Trim(DataChunk)
FullData = FullData & DataChunk
bytes.Clear(byt es, 0, CInt(tcpClient. ReceiveBufferSi ze))
If DataChunk="EOF, AppConfirmation String"
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...


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).

Otherwise, try putting a Counter within your main Loop with output going
to the Immediate Window, or using Debug.Print(Dat aChunk) 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.
Apr 20 '06 #2
Hi,

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(Dat aChunk) 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.

--
Greets,
Arkadiusz 'Winger' Slusarczyk
Republic of Ireland
Apr 20 '06 #3
Winger wrote:
Hi,

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(Dat aChunk) 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.

All of the above would still indicate to me that you are indeed looking
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.
Apr 20 '06 #4
ShaneO wrote:
All of the above would still indicate to me that you are indeed looking
at a re-entrant issue. It would appear your "Function" is being
simultaneously executed more than once.
I use threading (ThreadPool) to launch new thread that handles incoming
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
REM) your "Dim FullData as String" line and declare it in the General
Declarations section at the top of your program.


I've tried that, result was identical...

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
Apr 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1536
by: Klatuu | last post by:
Whew, I've struggled my way through figuring out how to use XML to transport data..now I can imagine what having a baby is like :) But, I'm stuck now. I generate the XML (single table, no indexes) and populate a dataset using READXML. I then merge the contents of that DS (call it DS1) with a second DS (call it DS2) that I've created on the form that will be used to process the data transfer. I did that so my SQL would be generated (I...
3
1881
by: Patrick | last post by:
I have got 2 XML documents, both of which conform to the same XSD Schema, which define possible optional elements. The 2 XML documents contain 2 disjoint set of XML elements. What is the best, easiest, most efficient way of merging the 2 XML Documents? Can I use DataSet.Merge() facility in ADO.NET?? Any pre-requisites? Any other suggestions?
2
5558
by: Emmett Power | last post by:
Hi, I have an Access table with a number of records which refer to the same person but with data in different fields. So for example the table would look like this: Name..............Field 1...................Field 2 Fred Smith........Red John Brown........Blue Fred Smith...................................Truck
1
4941
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word 1. Query..I want to keep the fields seperatred. I do not want to sent on field with all accumulated languages from one person to Word. Each language should appear in the document in a separate cell Cross tables are not delivering the result I...
2
1348
by: Dan Cooper | last post by:
I've got two datasets, each containing a single data table. dstDataSetA.Tables("TableA") dstDataSetB.Tables("TableB") I want to merge them together and delete any non-matching rows. dstDataSetB.Merge(dstDataSetA) doesn't do this. Any ideas or suggestions gratefully received.
1
1292
by: Jim Adams | last post by:
My ASP.Net (VB.Net) app needs to display a filled in form to a web user from the following: a) read HTML form files (not ascx) dynamically from disk (e.g. form.html) b) read its corresponding submitted values from disk (e.g. form.xml) The form data should be merged back into the HTML form so that when displayed to the user, the form looks exactly like it did the moment before
7
3932
by: Crirus | last post by:
Hi all! I use a webClient for requesting data from a server of mine. Should I worry about long ammount of data sent by server in the client side? Or, another way, should I send some kind of a terminator sign in the data in order to realise in the client that all data arrived? -- Ceers, Crirus
12
1407
by: google_groups3 | last post by:
Hi all. I currently have 2 text files which contain lists of file names. These text files are updated by my code. What I want to do is be able to merge these text files discarding the duplicates. And to make it harder (or not???!!) my criteria for defining the duplicate is the left 15 (or so) characters of the file path. Help, as always, is greatly appreciated!
1
1742
by: Big X | last post by:
I have already achieved this in access and was trying with straight SQL earlier I would just like to know what I'm doing wrong in sql or what syntax I'm missing. I have three tables with identical data that was created from .txt delimited files I have received. I tried the following code. SELECT VIN, OtherID, Rego, DriverName, OwnerName, VehicleDescription, ExpiryDate, Address, City, Postcode, State INTO Iload FROM STDhy60, STDhy59,...
0
8198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8642
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8444
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5549
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.