I am new to C#, and I've tried what seems to be everything, and the error Object Refference is Not Set to an Instance of an Object. I'm using the Mono C# compiler and here is the complete code to my program thus far. Can anyone tell me what's wrong?Code:using System; using System.IO; using System.Net; using System.Net.Sockets; using System.Text; // Program start class public class Users { public Users() { public TcpClient client = new TcpClient(); public bool LoggedOn = false; public NetworkStream stream = new NetworkStream(); } } class Listener { // Main begins program execution. public static void Main() { Int32 port = 1337; IPAddress localhost = IPAddress.Parse("127.0.0.1"); TcpListener listener = new TcpListener(localhost, port); listener.Start(); bool program_run = true; int i = 0; int stream_len = 0; Users[] user = new Users[300]; Byte[] bytes = new Byte[1024]; string dat=" "; while (program_run) { if (listener.Pending()) { i=0; while (!(user[i].LoggedOn)) { i++; } user[i].LoggedOn=true; user[i].client=listener.AcceptTcpClient(); user[i].stream=user[i].client.GetStream(); Console.WriteLine("Connected!"); } i=0; while (i<301) { if (user[i].LoggedOn) { if (user[i].stream.Length>0) { bytes = new Byte[user[i].stream.Length]; stream_len = user[i].stream.Read(bytes,0,stream_len); dat = Encoding.ASCII.GetBytes(bytes, 0, stream_len); Console.WriteLine("Received Data: {0}", stream_len); } } i=0; } } } }




Reply With Quote