我有这堂课:
class NetworkManager {
public void Connect(IPAddress address, int port, Action callback) {
Socket socket = new Socket(...);
socket.BeginConnect(address, port, r => EndConnect(r, socket, callback), null);
}
private void EndConnect(IAsyncResult r, Socket socket, Action callback) {
//End the connection and call the callback method
}
}
这种发送多个状态对象的方法好吗?
如果我把开始放在一个循环中,我还会通过正确的套接字吗?
Socket socket;
for(...){
socket = new Socket(...);
socket.BeginConnect(address, port, r => EndConnect(r, socket, callback), null);
}
我觉得应该有更正确的方法,有什么建议吗?