Networkstream returns ArgumentOutOfRangeException

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Since this issue encompasses so many things - I have to generally post it I
guess.

I'm building an application for a Wireless PDA - when it is connected to the
Network I tested a TCPListener & TCPClient connection from the Server to the
PDA. The connection allows me to Send from the PDA to the Server - but the
PDA will not read what the Server writes. I copied the exact information from
Microsofts Website on TCP basics - with some changes. Even disabled Firewall
Security - same. The PDA will download webpages, the Server can ping it - but
it will not receive.

Its an HP iPAQ rx3100 if that matters with Windows CE 4.2 2003 - Server is
running Windows 2003 Standard - and I am using Visual Studio 2003.NET to test
- the PDA also has OpenNETCF 1.2 with /cfAES pack.
 
Dustin B said:
Since this issue encompasses so many things - I have to generally post it I
guess.

I'm building an application for a Wireless PDA - when it is connected to the
Network I tested a TCPListener & TCPClient connection from the Server to the
PDA. The connection allows me to Send from the PDA to the Server - but the
PDA will not read what the Server writes. I copied the exact information from
Microsofts Website on TCP basics - with some changes. Even disabled Firewall
Security - same. The PDA will download webpages, the Server can ping it - but
it will not receive.

Its an HP iPAQ rx3100 if that matters with Windows CE 4.2 2003 - Server is
running Windows 2003 Standard - and I am using Visual Studio 2003.NET to test
- the PDA also has OpenNETCF 1.2 with /cfAES pack.

You haven't said exactly what happens, or posted any code.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
Jon Skeet said:
You haven't said exactly what happens, or posted any code.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Server
-------
Dim TcpC as New TcpListener(IPAddress.Parse("192.168.1.5"), 8500)
TcpC.Start()

Dim tcpclient as TcpClient = TcpC.AcceptTcpClient
Dim ns as NetworkStream = tcpclient.GetStream
Dim bytes() as Byte
bytes = System.Text.Encoding.ASCII.GetBytes("Testing Connection Write")
ns.Write(bytes, 0, bytes.length)
tcpclient.Close()
TcpC.Stop()


Client
------
Dim tcpc As New TcpClient
tcpc.Connect(IPAddress.Parse("192.168.1.5"), 8500)
Dim bytes(30000) As Byte
Dim NS As NetworkStream = tcpc.GetStream
NS.Read(bytes, 0, CInt(tcpc.ReceiveBufferSize))

bytes returns as IsNothing(bytes) = True
 
Dustin B said:
Server
-------
Dim TcpC as New TcpListener(IPAddress.Parse("192.168.1.5"), 8500)
TcpC.Start()

Dim tcpclient as TcpClient = TcpC.AcceptTcpClient
Dim ns as NetworkStream = tcpclient.GetStream
Dim bytes() as Byte
bytes = System.Text.Encoding.ASCII.GetBytes("Testing Connection Write")
ns.Write(bytes, 0, bytes.length)
tcpclient.Close()
TcpC.Stop()


Client
------
Dim tcpc As New TcpClient
tcpc.Connect(IPAddress.Parse("192.168.1.5"), 8500)
Dim bytes(30000) As Byte
Dim NS As NetworkStream = tcpc.GetStream
NS.Read(bytes, 0, CInt(tcpc.ReceiveBufferSize))

bytes returns as IsNothing(bytes) = True

Please read
http://www.pobox.com/~skeet/csharp/incomplete.html
 
Jon Skeet said:

I am serious that's it. On the last line of the Client Script it returns the
ArgumentOutOfRangeException - the most I can figure is that the byte array
when returned is empty - however the Client does say there is Data Available.
I have two version the full one - not shown - and the test one (shown) both
return the same error. I have had the PDA unplugged from ActiveSync to test -
tested the Firewall/Router rewired the Network - nothing same error. I'm
almost tempted to think its hardware or another layer of the PDA but the PDA
is able to write to the stream if I swap the Client/Listener Read/Write
commands.
 
Dustin B said:
I am serious that's it.

No it's not. You didn't post a complete program. If you don't believe
me, try cutting and pasting your code into an empty text editor, and
then compiling it without adding anything more.
On the last line of the Client Script it returns the
ArgumentOutOfRangeException

And what's the message of the ArgumentOutOfRangeException? It should at
least tell you what argument it is that's out of range.
 
Jon Skeet said:
No it's not. You didn't post a complete program. If you don't believe
me, try cutting and pasting your code into an empty text editor, and
then compiling it without adding anything more.


And what's the message of the ArgumentOutOfRangeException? It should at
least tell you what argument it is that's out of range.
Well I took out the silly stuff like Imports and Sub New - but that was all
autocreated by VS.NET anyway. It never told me what the Argument was. But I
just found the solution anyway. Seems that it was being thrown by the
NetworkStream itself.

NetworkStream.Read(bytes as Byte[], position (as Integer), length (as
Integer)) as Integer

only after some digging did I notice the return at the end - as soon as I
captured the return somewhere - the String sent along the stream was
captured. Strange.
 
Dustin B said:
Well I took out the silly stuff like Imports and Sub New - but that was all
autocreated by VS.NET anyway.

That's not silly stuff. It makes life *much* easier for someone to
reproduce the problem. I don't want to have to launch Visual Studio in
order to test your code - I want to be able to copy your code into a
text editor, compile it and run it. If it's going to take longer than
that, I'll move onto a message where someone is willing to follow
instructions to make it easier for me to help them - that way I get to
help more people.
It never told me what the Argument was.

Not in the message? Was there a message at all? You never posted it.
But I just found the solution anyway. Seems that it was being thrown
by the NetworkStream itself.

NetworkStream.Read(bytes as Byte[], position (as Integer), length (as
Integer)) as Integer

only after some digging did I notice the return at the end - as soon as I
captured the return somewhere - the String sent along the stream was
captured. Strange.

I don't see how using the return value could affect things at all. But
without a short but complete test program, I'm not going to bother to
investigate further...
 
Back
Top