News  [SoftwareSite

Latest News
Older News
RSS Feed
 
Complete Projects
Useful Classes
Top Downloads
Message Board
AllAPI.net
 
Send Comments
Software License
Mentalis.org Buttons
Donate
 
Forums -> Security Library Forum
 
Request for help  
by Tarek Salah SObh [tarekbox2000 at arabia dot com]
posted on 2004/05/05

I have a problem in the secure network stream returned by the method SecureTcpListener.GetStream().
It always raises the exception (Object refrence not set to an instance of an object)when trying to read from the network stream using the method SecureNetworkStream.Read().

by Pieter Philippaerts [Pieter at mentalis dot org]
posted on 2004/05/13

Can you post the source code you're using right now that throws the exceptions..?

by Tarek Sobh
posted on 2004/05/16

// Client's code
static void Main(string[] args)
{
byte[] message = Encoding.ASCII.GetBytes("server helloooooo");
SecurityOptions so = new SecurityOptions(SecureProtocol.None);
SecureTcpClient sc = new SecureTcpClient("node4",5005,so);


SecureNetworkStream ns = sc.GetStream();


ns.Write(message,0,message.Length);
Console.WriteLine("data sent");
ns.Close();
sc.Close();
Console.Read();
}
//Server's code
static void run()
{
byte[] message = null;
SecurityOptions so = new SecurityOptions(SecureProtocol.None);
SecureTcpListener s = new SecureTcpListener(5005,so);
s.Start();
SecureTcpClient sc = s.AcceptTcpClient();
SecureNetworkStream ns = sc.GetStream();
try
{
ns.Read(message,0,message.Length);
Console.WriteLine("data received ");
Console.WriteLine(Encoding.ASCII.GetString(message));
}
catch(Exception e)
{
Console.WriteLine(e.Message.ToString());
}
sc.Close();
s.Stop();
Console.Read();
}

by Pieter Philippaerts [Pieter at mentalis dot org]
posted on 2004/05/16

The ArgumentNullException is because you use the message parameter without initializing it to a valid array of bytes.
You should change the declaration of message to something like this:
byte[] message = new byte[1024];

 

Copyright © 2002-2007, The Mentalis.org Team. All rights reserved.
This site is located at http://www.mentalis.org/
Send comments to the webmaster.