473,396 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Buffer overlap

I am getting over lapping data while sending and receiving data in a tcp listener I am working on. How does one reset or clear the buffer or bytes so they don't carry over to the next send or receive?

Thanks in advance!

Partial Example:

' Client sends:
TempS = curAdd.ToString & "................................................. .................................................. .."

' Padding the end of the IP address so I can trim(".") when received because I couldn't trim the free space at the end.

Buffer = System.Text.Encoding.Default.GetBytes(TempS.ToStri ng)

Client.GetStream().Write(Buffer, 0, Buffer.Length)

' The Server Receives:

While Not StopListener

If CurSocket.Available > 0 Then

' 1. Receive IP Address from client:

Bytes = CurSocket.Receive(Buffer, Buffer.Length, 0)

SyncLock CurThread

clientV = (System.Text.Encoding.Default.GetString(Buffer)).T oString

clientV = clientV.Trim(".")

Buffer.Clear(Buffer, Buffer.Length, 0)

On the next send / receive I am getting leftover ........... in the string.

THANKS!

Nov 21 '05 #1
3 1452
Kenneth,

I'm not sure I understand the problem, but ...

Buffer = System.Text.Encoding.Default.GetBytes(TempS.ToStri ng)
I'd recommend using an encoding other than Default (such as UTF-8),
because the default can be different on different systems.

Buffer.Clear(Buffer, Buffer.Length, 0)


Since you specify a length of xero here, nothing will be cleared.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
When I send this: TempS = curAdd.ToString &
"................................................. .................................................. ."
to the server I then trim(".") to get rid of the periods. Then the server
sends four messages back to the client depending on the processes that takes
place. Finally the client Sends: "PCNAME-Scheduled" to the server and the
server receives "........ting". It appears as though its pieces of previous
buffer information.

I hope I explained the issue!

Thanks for the HELP!

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
Kenneth,

I'm not sure I understand the problem, but ...

Buffer = System.Text.Encoding.Default.GetBytes(TempS.ToStri ng)


I'd recommend using an encoding other than Default (such as UTF-8),
because the default can be different on different systems.

Buffer.Clear(Buffer, Buffer.Length, 0)


Since you specify a length of xero here, nothing will be cleared.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 21 '05 #3
Hi

Firstly I think you may try the code in the link below for client/server.
TcpListener Class
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemnetsocketstcplistenerclasstopic.asp
TcpClient Class
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemNetSocketsTcpClientClassTopic.asp

If you still have any concern, can you build a simple reproduce sample and
send to me via removing "online" from my email address.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #4

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

Similar topics

0
by: dag | last post by:
Hi! I would like to do an overlap window, over my main window (of my application), with a Progress Bar. Exactly when I push a button of my application I want show a window, with a Progress bar,...
2
by: John Baker | last post by:
HI; I have a table where the user is entering data which shows scheduling for member of teams. One problem we have encountered is that sometimes the inputter (is this a word) puts in dates for...
5
by: Paolo | last post by:
Hi all! I have to create an application that receive some packet from an interface and builds a file from those. In the header there are three fields: one is the total lenght of the file, one is...
13
by: Mike S | last post by:
I came across the following paragraph in the "Semantics" section for simple assignment in N1124 (C99 draft) and I'm wondering if I'm interpreting it right: 6.5.16.1p3: If the value being...
26
by: Andrew Poelstra | last post by:
I hacked this together this morning so that I could shift my out-of- space code away from the rest of my logic. I wanted to allow array syntax on my dynamic buffers, so I manually created a struct...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
10
by: Jonathan Sion | last post by:
Hi, I got a large text string, and a bunch of regular expression patterns i need to find within the string. in other words, to find all the 'tokens' inside it. of course I could use the regexp...
5
by: liketofindoutwhy | last post by:
It seems like there are only 4 methods to overlap 2 images using CSS? There are two images, each with its own URL. Using CSS, there seems to be 2 ways to overlap them (the task is actually to put...
16
by: Steven D'Aprano | last post by:
On Tue, 09 Sep 2008 14:59:19 -0700, castironpi wrote: You've created a solution to a problem which (probably) only affects a very small number of people, at least judging by your use-cases....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.