471,596 Members | 860 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Networkstream Returning Null Value

This is coming from a Windows 2003 Server to a HP Pocket PC (WinCE 2003)
over 802.11b. The device is on the Network and can be pinged, it can write
data to the Server stream - but not read the reverse.

I'd appreciate any help.

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() = System.Text.Encoding.ASCII.GetBytes("Testing Connection
Write")
ns.Write(bytes, 0, bytes.length)
tcpclient.Close()
TcpC.Stop()

Mobile
------
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))

it fails on the last line giving an ArgumentOutOfRangeException saying that
IsNothing(bytes) = True.

--
Message posted via http://www.dotnetmonster.com
Nov 21 '05 #1
2 1723
Hi Dustin,
Dim bytes(30000) As Byte
You forgot to instantiate your array:

---
Dim bytes(30000) As New Byte
---

Give that a go. Without the new operator your bytes variable will be
Nothing (as it hasn't been instantiated yet and hence the error. :)

Regards,
-Adam Goossens.

Dustin Brisebois via DotNetMonster.com wrote: This is coming from a Windows 2003 Server to a HP Pocket PC (WinCE 2003)
over 802.11b. The device is on the Network and can be pinged, it can write
data to the Server stream - but not read the reverse.

I'd appreciate any help.

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() = System.Text.Encoding.ASCII.GetBytes("Testing Connection
Write")
ns.Write(bytes, 0, bytes.length)
tcpclient.Close()
TcpC.Stop()

Mobile
------
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))

it fails on the last line giving an ArgumentOutOfRangeException saying that
IsNothing(bytes) = True.

Nov 21 '05 #2
Oops. I mis-read the exception type :) I think I need a bit more
sleep...my head feels groggy :P

You may have received more data than your array can handle (the
ArgumentOutOfRange exception is a good clue to that). You should only
read as much data as you have space to handle it.

Try something like this instead:

---
NS.Read(bytes, 0, bytes.Length)
---

Or, dimension your array to accomodate all of the data received:

---
Dim bytes(tcpc.Length) As Byte
---

As for my stupid comment about instantiating your array: ignore it. I
don't know what I was thinking - you can't instantiate arrays with New.
I must be tired.

Sorry :)
Regards,
-Adam.

Dustin Brisebois via DotNetMonster.com wrote:
This is coming from a Windows 2003 Server to a HP Pocket PC (WinCE 2003)
over 802.11b. The device is on the Network and can be pinged, it can write
data to the Server stream - but not read the reverse.

I'd appreciate any help.

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() = System.Text.Encoding.ASCII.GetBytes("Testing Connection
Write")
ns.Write(bytes, 0, bytes.length)
tcpclient.Close()
TcpC.Stop()

Mobile
------
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))

it fails on the last line giving an ArgumentOutOfRangeException saying that
IsNothing(bytes) = True.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by JKop | last post: by
9 posts views Thread by Thomas Mlynarczyk | last post: by
reply views Thread by Maart_newbie | last post: by
4 posts views Thread by Rob | last post: by
Parul Bagadia
11 posts views Thread by Parul Bagadia | last post: by
1 post views Thread by sbowman | last post: by
reply views Thread by leo001 | last post: by

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.