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();
} |