473,395 Members | 1,702 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,395 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 1811
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: JKop | last post by:
AnyClass Blah() { AnyClass poo; return poo; } As we all know, in the above, the compiler is entitled to:
9
by: Thomas Mlynarczyk | last post by:
Hi, It seems to be a generally adopted convention to have a function return FALSE in case of an error. But if a function is supposed to return a boolean anyway, one cannot distinguish anymore...
7
by: bjose21 | last post by:
Hello, I've been searching the web for quite some time to resolve the problem of "1/1/1900" returning in a datetime field in SQL that resulted from a blank (not NULL) value being passed to it...
0
by: Maart_newbie | last post by:
Hi all, I've got a question about returning the value of a pk-column to a DataTable after inserting a row (via a data-adapter) using MySql5. Here is the SQL and code concerned: ...
4
by: Rob | last post by:
Hi, I have a label that I'm trying to make invisible on the client side using the OnClientClick event for a button. In the javascript function I have the following code: var x =...
11
Parul Bagadia
by: Parul Bagadia | last post by:
I m returning a value of pointer of a structure from one function to main; but whenever it comes in main it becomes NULL... i used another pointer in main and equated its value to returning pointer...
1
by: sbowman | last post by:
I have the following CASE statement in a view: (SELECT CASE WHEN ISNULL(.., NULL) = NULL THEN .(..) ELSE .(..) + ', ' + .. END) AS ContactNameAndTitle It works perfectly when...
3
by: pbellem | last post by:
Is there a way to write a select that will return a null value for a row that does not exist? for example: Table A productId - type id - name - value 1 - 1 - Title - "Great Song" 1 - 2 -...
2
by: aaronharwood | last post by:
I have read dozens of existing responses on threads, that span the last 5 years or so, concerning this problem and while there are many solutions that appear to work for others - none work for me. ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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.