473,830 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Enc oding.Default.G etBytes(TempS.T oString)

Client.GetStrea m().Write(Buffe r, 0, Buffer.Length)

' The Server Receives:

While Not StopListener

If CurSocket.Avail able > 0 Then

' 1. Receive IP Address from client:

Bytes = CurSocket.Recei ve(Buffer, Buffer.Length, 0)

SyncLock CurThread

clientV = (System.Text.En coding.Default. GetString(Buffe r)).ToString

clientV = clientV.Trim(". ")

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

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

THANKS!

Nov 21 '05 #1
3 1469
Kenneth,

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

Buffer = System.Text.Enc oding.Default.G etBytes(TempS.T oString)
I'd recommend using an encoding other than Default (such as UTF-8),
because the default can be different on different systems.

Buffer.Clear(B uffer, 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 "........ti ng". 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.o rg> wrote in message
news:eW******** ******@TK2MSFTN GP09.phx.gbl...
Kenneth,

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

Buffer = System.Text.Enc oding.Default.G etBytes(TempS.T oString)


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/
frlrfsystemnets ocketstcplisten erclasstopic.as p
TcpClient Class
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemNetS ocketsTcpClient ClassTopic.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
1867
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, during the processing time. The first question is: Is it possible to have an overlap window? (I create my windows by the "CreateWindowEx" command) By which command
2
4801
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 an individual that overlap, creating all sorts of problems. One record is entered for each scheduled event (each one is a day in length or more), so that an individual will have multiple events on the table. For the purposes of this question,...
5
1561
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 the offset of the packet in the file and one is the lenght of the current packet. I made a function that gets all the packets and reconstruct the file. while(...) {
13
3168
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 stored in an object is read from another object that overlaps in any way the storage of the first object, then the overlap shall be exact and the two objects shall
26
3491
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 with malloc() and judicious use of void* pointers. I decided to post it because stuff like this is breeding ground for UB, and this group is good at finding it. (I had a dentist analogy for that, but it didn't work out.) Here's my code:
22
4048
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 receive 5 bytes buffer , I call the BeginReceive and then wait on AsyncWaitHandle.WaitOne() but it is signald imidiatly , and the next call to EndReceive return zero bytes length , also the buffer is empty. here is the code: public static byte...
10
1570
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 engine, the thing is, if I got 500 different patterns, this means 500 searches on the buffer. Does anybody has any general idea on how this could be sped up? In other words, I am looking to do what the old 'LEX' tool in unix used to do - one pass...
5
10880
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 a "play button" image with size 50 x 50 on top of the bigger image which is a video thumbnail size 200 x 150). 1) Use <div><img ><img ></divwith the play button as the second image and displayed relatively positioned to overlap the first...
16
1620
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. Who has a 4GB XML file, and how much crack did they smoke? Castironpi, what do *you* use this proof-of-concept module for? Don't
0
9641
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10769
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
10520
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
10196
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
6940
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
5775
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4408
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
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3070
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.