473,473 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Read Method

i´m reading some data from a socket object and when i call the read method
it returns 0 bytes to my byte array.

my code:
private void processRequest(){
byte[] buffer;

int numBytes = this._userSocket.Available;

if(numBytes > maxHeaderBytes){

numBytes = maxHeaderBytes;

}

buffer = new byte[numBytes];

try{

this._userSocket.Receive(buffer,0,numBytes,0); // HERE IS RETURNED AN EMPTY
ARRAY!!! AND Avaliable Property says that exists for exa,ple 800 bytes do be
read.

this._pacoteHttp = this._encoder.GetString(buffer);

if(this._pacoteHttp != String.Empty){

this.extractHeader();

}else{

throw new RequisicaoVaziaException("Empty request(??) " +
this._userSocket.Available + " bytes to be read",this._userSocket);

}

}

catch(SocketException ex){

throw new ConexaoEncerradaException("Connection closed" + ex.ToString());

}

}
Nov 15 '05 #1
5 1460
Lafayette <ld*@nospam.ldd.com> wrote:
i´m reading some data from a socket object and when i call the read
method it returns 0 bytes to my byte array.


Are you sure that numBytes is non-zero when you call the method? Can
you produce a short but complete example which demonstrates the
problem?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
thankz for the reply Jon,

I have an HTML form like this:

<html>
....
....
<form action=http://localhost:1010/SEND_MESSAGE>
<input type="text" name="MSG">
<input type="submit" name="sbmt">
</form>
.....
</html>

the data that i´m trying to read is comming from that html form.

my app listens on por 1010

in my main thread i have this code:

private void listener(){

this._listener = new
Socket(AddressFamily.InterNetwork,SocketType.Strea m,ProtocolType.Tcp);
this._listener.Bind(new IPEndPoint(IPAddress.Any,this._porta));
this._listener.Listen(this._porta);
while(true){
allDone.Reset();
this._listener.BeginAccept(new
AsyncCallback(this.onConnect),this._listener);
allDone.WaitOne();
}

}//listener

in onConnect event another thread is startd, the socket is passed as
contructor parameter of a class named Request
The Request class shoud read the http packet, split the querystring , post
data and so on.

when the processRequest Method is called, the avaliable property says that
are 700bytes do be read but when the read method runs, nothing is returned.

when it happens i get lost because the connection is closed by the client
(internet explorer) and i can´t send anything back to my user

thankz in advance

Lafayette

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Lafayette <ld*@nospam.ldd.com> wrote:
i´m reading some data from a socket object and when i call the read
method it returns 0 bytes to my byte array.


Are you sure that numBytes is non-zero when you call the method? Can
you produce a short but complete example which demonstrates the
problem?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
What is the return value of Socket.Receive()?

This could be a problem with converting the byte[] to a string. Have you
used a debugger to step through this code and see what the array looks like
after the Receive() call?

--
Jared Parsons [MSFT]
ja******@online.microsoft.com
This posting is provided "AS IS" with no warranties, and confers no rights.
OR if you wish to include a script sample in your post please add "Use of
included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"

"Lafayette" <ld*@nospam.ldd.com> wrote in message
news:uJ**************@TK2MSFTNGP09.phx.gbl...
i´m reading some data from a socket object and when i call the read method
it returns 0 bytes to my byte array.

my code:
private void processRequest(){
byte[] buffer;

int numBytes = this._userSocket.Available;

if(numBytes > maxHeaderBytes){

numBytes = maxHeaderBytes;

}

buffer = new byte[numBytes];

try{

this._userSocket.Receive(buffer,0,numBytes,0); // HERE IS RETURNED AN EMPTY ARRAY!!! AND Avaliable Property says that exists for exa,ple 800 bytes do be read.

this._pacoteHttp = this._encoder.GetString(buffer);

if(this._pacoteHttp != String.Empty){

this.extractHeader();

}else{

throw new RequisicaoVaziaException("Empty request(??) " +
this._userSocket.Available + " bytes to be read",this._userSocket);

}

}

catch(SocketException ex){

throw new ConexaoEncerradaException("Connection closed" + ex.ToString());

}

}

Nov 15 '05 #4
Lafayette <ld*@nospam.ldd.com> wrote:
thankz for the reply Jon,

I have an HTML form like this:


<snip>

As I said before, it would help if you gave a *complete* program which
demonstrates the problem. If you could write a program I could just
compile and run with no changes, along with a full HTML page to load in
IE, it'll be much easier to find out what's wrong.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5
Jon,
I sent the files to you.
thankz in advance
Lafayette

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Lafayette <ld*@nospam.ldd.com> wrote:
thankz for the reply Jon,

I have an HTML form like this:


<snip>

As I said before, it would help if you gave a *complete* program which
demonstrates the problem. If you could write a program I could just
compile and run with no changes, along with a full HTML page to load in
IE, it'll be much easier to find out what's wrong.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #6

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

Similar topics

2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
1
by: Brian | last post by:
I'm having intermittent trouble with a call to the Read method of the HttpWebResponse object. I get an ArumentOutOfRangeException claiming that deep down inside of the Read method, the count...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
6
by: Samuel M. Smith | last post by:
I have been playing around with a subclass of dict wrt a recipe for setting dict items using attribute syntax. The dict class has some read only attributes that generate an exception if I try to...
2
by: Giulio Petrucci | last post by:
Hi everytbody, I'm experiencing some problems trying to asynchronously read data from a Socket object. What I do now is: 1) call th BeginReceive(...) method on the Socket object; 2) within the...
3
by: Osamede.Zhang | last post by:
I have some code like this: SqlCommand cmd = new SqlCommand("get_storeid_byuser", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@username", SqlDbType.VarChar, 50).Value...
2
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it...
0
by: martinmercy2001 | last post by:
Could any body help me with creating a ring buffer class using a string. use memory circular buffer not an IO buffer. just read, write and seek method. Read method should take anumber and return the...
0
by: vishnu | last post by:
Hi, Am trying to post the data over https and am getting error in httpwebresponse.getResponseStream.Please help me to get rid of this issue. Here is the message from immediate window ...
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.