G
Guest
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.IPAddress IPAddress = System.Net.IPAddress.Parse(strPrtrIPAddr);
System.Net.IPEndPoint IPEndPoint = new System.Net.IPEndPoint(IPAddress,
intPrtrPort);
// Create a TCP/IP socket.
rsocClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
// Connect to the remote end point.
rsocClient.BeginConnect(IPEndPoint, new AsyncCallback(ConnectCallback),
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.AsyncState;
// Complete the connection.
socClient.EndConnect(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.IPAddress IPAddress = System.Net.IPAddress.Parse(strPrtrIPAddr);
System.Net.IPEndPoint IPEndPoint = new System.Net.IPEndPoint(IPAddress,
intPrtrPort);
// Create a TCP/IP socket.
rsocClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
// Connect to the remote end point.
rsocClient.BeginConnect(IPEndPoint, new AsyncCallback(ConnectCallback),
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.AsyncState;
// Complete the connection.
socClient.EndConnect(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.