hi all,
i am using asynchronous sockets in my program. i'm able to establish the connection and the application works just fine. my problem is w/ disconnecting. i seem to be able to disconnect the client but is unable to do this w/ the server. below are portions of my code for establishing the server, the client, as well as the code that i'm using for disconnecting.
appreciate if somebody could tell me what i'm doing wrong.
thanks!
declarations
-----------------
int PortNum = 0;
string Hostname = "localhost";
public AsyncCallback pfnWorkerCallBack; //server
public Socket m_socListener; //server
public Socket m_socWorker; //server
public Socket m_socClient; //client
server code
----------------
m_socListener = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint ( IPAddress.Any , PortNum);
m_socListener.Bind( ipLocal );
m_socListener.Listen (4);
m_socListener.BeginAccept(new AsyncCallback ( OnClientConnect ),null);
// etc.
client code
-----------
m_socClient = new Socket (AddressFamily.InterNetwork,SocketType.Stream ,ProtocolType.Tcp );
IPHostEntry ipEntry = Dns.GetHostByName(Hostname);
IPAddress ip = ipEntry.AddressList[0];
IPEndPoint ipEnd = new IPEndPoint (ip.Address, PortNum);
m_socClient.Connect ( ipEnd );
//etc.
disconnect code
----------------
for client
----------
m_socClient.Close ();
m_socClient = null;
for server
----------
m_socWorker.Close ();
m_socWorker = null;
m_socListener.Close();
m_socListener = null;
i am using asynchronous sockets in my program. i'm able to establish the connection and the application works just fine. my problem is w/ disconnecting. i seem to be able to disconnect the client but is unable to do this w/ the server. below are portions of my code for establishing the server, the client, as well as the code that i'm using for disconnecting.
appreciate if somebody could tell me what i'm doing wrong.
thanks!
declarations
-----------------
int PortNum = 0;
string Hostname = "localhost";
public AsyncCallback pfnWorkerCallBack; //server
public Socket m_socListener; //server
public Socket m_socWorker; //server
public Socket m_socClient; //client
server code
----------------
m_socListener = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint ( IPAddress.Any , PortNum);
m_socListener.Bind( ipLocal );
m_socListener.Listen (4);
m_socListener.BeginAccept(new AsyncCallback ( OnClientConnect ),null);
// etc.
client code
-----------
m_socClient = new Socket (AddressFamily.InterNetwork,SocketType.Stream ,ProtocolType.Tcp );
IPHostEntry ipEntry = Dns.GetHostByName(Hostname);
IPAddress ip = ipEntry.AddressList[0];
IPEndPoint ipEnd = new IPEndPoint (ip.Address, PortNum);
m_socClient.Connect ( ipEnd );
//etc.
disconnect code
----------------
for client
----------
m_socClient.Close ();
m_socClient = null;
for server
----------
m_socWorker.Close ();
m_socWorker = null;
m_socListener.Close();
m_socListener = null;