T
tcomer
Hello - I'm working on a simple instant messenger application, and I
have it working but in order to achieve the results I want I need to
make a few changes. The problem is that I have a class that contains a
Socket. If I try to assign a socket reference to the socket in the
Client class a NullReferenceException is thrown. I know that
m_mainSocket is valid because it works fine if I declare an array of
sockets instead of using the Client class. Am I overlooking something
possibly? Any help is appreciated.
private Client[] m_Client = new Client[10];
private Socket m_mainSocket = new Socket(<params here>);
....
....
public void ClientConnect(IAsyncResult result)
{
try
{
m_Client[0].m_clientSocket = m_mainSocket.EndAccept(result); //
line 292
}
catch(NullReferenceException nre){ MessageBox.Show(nre.StackTrack);}
// finds null reference at line 292
....
....
public class Client{
public System.Net.Sockets.Socket m_clientSocket;
public string m_clientName;
}
I've also tried initializing m_clientSocket using a constructor in the
Client class but that doesn't seem to solve the problem.
have it working but in order to achieve the results I want I need to
make a few changes. The problem is that I have a class that contains a
Socket. If I try to assign a socket reference to the socket in the
Client class a NullReferenceException is thrown. I know that
m_mainSocket is valid because it works fine if I declare an array of
sockets instead of using the Client class. Am I overlooking something
possibly? Any help is appreciated.
private Client[] m_Client = new Client[10];
private Socket m_mainSocket = new Socket(<params here>);
....
....
public void ClientConnect(IAsyncResult result)
{
try
{
m_Client[0].m_clientSocket = m_mainSocket.EndAccept(result); //
line 292
}
catch(NullReferenceException nre){ MessageBox.Show(nre.StackTrack);}
// finds null reference at line 292
....
....
public class Client{
public System.Net.Sockets.Socket m_clientSocket;
public string m_clientName;
}
I've also tried initializing m_clientSocket using a constructor in the
Client class but that doesn't seem to solve the problem.