473,408 Members | 2,832 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,408 software developers and data experts.

Increment socket receive buffer pointer?

In C# 2.0, I am processing data from a socket. There are cases, where
I pull 12 bytes from the socket and determine that the next X bytes
should be ignored, where X is determined by observing each 12 bytes of
data.

Currently, I am allocating a byte array of X bytes and using
Socket.Receive(...) to pull the remaining X bytes off the socket and
discarding them:

byte[] discardData = new byte[numBytesToDiscard];
socket.Receive(discardData, 0, numBytesToDiscard, SocketFlags.None);

Is there a way in C# to just push the socket pointer up by X bytes
without having to copy the bytes into an array?

Jan 19 '07 #1
2 2565
No. That data will be in the internal buffers and needs to be read. From a
network perspective you should always read as much as you can each read,
then process that chunk as you need instead many small reads.

--
William Stacey [C# MVP]

"O.B." <fu******@bellsouth.netwrote in message
news:11**********************@q2g2000cwa.googlegro ups.com...
| In C# 2.0, I am processing data from a socket. There are cases, where
| I pull 12 bytes from the socket and determine that the next X bytes
| should be ignored, where X is determined by observing each 12 bytes of
| data.
|
| Currently, I am allocating a byte array of X bytes and using
| Socket.Receive(...) to pull the remaining X bytes off the socket and
| discarding them:
|
| byte[] discardData = new byte[numBytesToDiscard];
| socket.Receive(discardData, 0, numBytesToDiscard, SocketFlags.None);
|
| Is there a way in C# to just push the socket pointer up by X bytes
| without having to copy the bytes into an array?
|
Jan 20 '07 #2
O.B. wrote:
byte[] discardData = new byte[numBytesToDiscard];
socket.Receive(discardData, 0, numBytesToDiscard, SocketFlags.None);
Don't forget that you *must* look at the return value of Socket.Receive
to find out how many bytes were actually read. It is not an error for it
to be less than the number you looked for, but if it is zero, then it's
the other end is closed etc.
Is there a way in C# to just push the socket pointer up by X bytes
without having to copy the bytes into an array?
It's better to implement your own buffering solution, for better
performance.

-- Barry

--
http://barrkel.blogspot.com/
Jan 20 '07 #3

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

Similar topics

4
by: Stephan Steiner | last post by:
Hi I have a networking application that periodically needs to go into sleep mode (from an application point of view, I'm simply suspending the receiver thread until it's time to start listening...
4
by: Brian Rice | last post by:
I have a socket application that is sending and receiving packets asynchronously. It works great except, when I receive packets that are larger than my receive buffer which then generate several...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
2
by: Craig | last post by:
Hi I listen on a port, when data is received I raise an event (OnMessageReceived) in the while loop as follows: private void WaitForConnection() { TcpListener listener = new...
5
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of...
13
by: coloradowebdev | last post by:
i am working on basically a proxy server that handles requests via remoting from clients and executes transactions against a third-party server via TCP. the remoting site works like a champ. my...
9
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so...
3
by: Eric Marthinsen | last post by:
Hello- I'm trying to create a console app that will accept an incoming HTTP request and output the information of the request to the console. The code is pretty simple - here's what it looks...
1
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.