Hello,
Whats the significance of beginconnect() in socket programming? Actually i encountered an error because i did an experiment:
- I had a device connected on network to my PC application.
- I then removed the LAN cable.
- After sometime i again reconnected the LAN cable back to the device. My PC application threw an error saying :
"use beginconnect to connect once again and that too to a different endpoint".
- So i tried out another thing: i wrote the following code:
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ip = new IPEndPoint(IPAddress.Parse("172.16.3.230"),502);
s.Connect(ip);
do
{
Console.WriteLine("connect?");
string s1 = Console.ReadLine();
if (s1 == "y")
{
s.Connect(ip);
}
} while (true);
}
- In this i press "y" to reconnect again. However this time it gives another error saying:
"You are already connected to that endpoint". The error here is different. Does this imply that beginconnect is the best option to reconnect?
I read about Socket.BeginConnect(): its syntax is :
public IAsyncResult BeginConnect(
IPAddress[] addresses, ------1
int port, ------2
AsyncCallback requestCallback, ------3
Object state ------4
)
Can someone please explain me the 4th argument?
Thanks,
- Rahul