Hi,
I am having some problem with callback used in socket implementation.
private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref
Socket rsocClient)
{
try
{
// Create remote end point.
System.Net.IPAd dress IPAddress = System.Net.IPAd dress.Parse(str PrtrIPAddr);
System.Net.IPEn dPoint IPEndPoint = new System.Net.IPEn dPoint(IPAddres s,
intPrtrPort);
// Create a TCP/IP socket.
rsocClient = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p);
// Connect to the remote end point.
rsocClient.Begi nConnect(IPEndP oint, new AsyncCallback(C onnectCallback) ,
rsocClient);
// Signal the connection event to wait.
mevtConnectDone .WaitOne();
}
catch(Exception objException)
{
throw objException;
}
}
private static void ConnectCallback (IAsyncResult IResult)
{
try
{
// Retrieve the socket from the state object.
Socket socClient = (Socket) IResult.AsyncSt ate;
// Complete the connection.
socClient.EndCo nnect(IResult);
// Signal that the connection has been made.
mevtConnectDone .Set();
}
catch(Exception objException)
{
mevtConnectDone .Set();
throw objException;
}
}
Please check the above two methods. Callback throws an error at EndConnect
but it is not propogated to the parent function. How to solve this problem.
Please help me asap. Thanks in advance.
I am having some problem with callback used in socket implementation.
private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref
Socket rsocClient)
{
try
{
// Create remote end point.
System.Net.IPAd dress IPAddress = System.Net.IPAd dress.Parse(str PrtrIPAddr);
System.Net.IPEn dPoint IPEndPoint = new System.Net.IPEn dPoint(IPAddres s,
intPrtrPort);
// Create a TCP/IP socket.
rsocClient = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p);
// Connect to the remote end point.
rsocClient.Begi nConnect(IPEndP oint, new AsyncCallback(C onnectCallback) ,
rsocClient);
// Signal the connection event to wait.
mevtConnectDone .WaitOne();
}
catch(Exception objException)
{
throw objException;
}
}
private static void ConnectCallback (IAsyncResult IResult)
{
try
{
// Retrieve the socket from the state object.
Socket socClient = (Socket) IResult.AsyncSt ate;
// Complete the connection.
socClient.EndCo nnect(IResult);
// Signal that the connection has been made.
mevtConnectDone .Set();
}
catch(Exception objException)
{
mevtConnectDone .Set();
throw objException;
}
}
Please check the above two methods. Callback throws an error at EndConnect
but it is not propogated to the parent function. How to solve this problem.
Please help me asap. Thanks in advance.
Comment