c# - Console program, static methods, socket becomes null -


class program {     static socket m_sock;      static void main(string[] args)     {         socket m_sock= new socket(addressfamily.internetwork, sockettype.stream, protocoltype.tcp);         .         .         .         m_sock.connect(ipendlocalhost);         sendrequest("command");     }      static void sendrequest(string scommand)     {        .        .      **m_sock.send(szcommand, ibytestosend, socketflags.none);**      } 

when comes send method nullreferenceexception. in debug (i added m_sock watch) see when program enters sendrequest method m_sock becomes null. can't understand why happening , problem is. please help.

m_sock defined internal main @ class level, don't have define again in main, initialize it, like:

static void main(string[] args)     {         m_sock= new socket(addressfamily.internetwork, sockettype.stream, protocoltype.tcp); 

notice socket removed.

currently main method initializing local m_sock, , why class level m_sock staying null, later when access in static method getting exception.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -