本文整理汇总了C#中System.Net.Sockets.Socket.BeginConnect方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.BeginConnect方法的具体用法?C# Socket.BeginConnect怎么用?C# Socket.BeginConnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.Socket
的用法示例。
在下文中一共展示了Socket.BeginConnect方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IPEndPoint
IPHostEntry lipa = Dns.Resolve("host.contoso.com");
IPEndPoint lep = new IPEndPoint(lipa.AddressList[0], 11000);
Socket s = new Socket(lep.Address.AddressFamily,
SocketType.Stream,
ProtocolType.Tcp);
try{
while(true){
allDone.Reset();
Console.WriteLine("Establishing Connection");
s.BeginConnect(lep, new AsyncCallback(Async_Send_Receive.Connect_Callback), s);
allDone.WaitOne();
}
}
catch (Exception e){
Console.WriteLine(e.ToString());
}
示例2: ManualResetEvent
public static ManualResetEvent allDone =
new ManualResetEvent(false);
// handles the completion of the prior asynchronous
// connect call. the socket is passed via the objectState
// paramater of BeginConnect().
public static void ConnectCallback1(IAsyncResult ar)
{
allDone.Set();
Socket s = (Socket) ar.AsyncState;
s.EndConnect(ar);
}
示例3: BeginConnect1
// Asynchronous connect using the host name, resolved via
// IPAddress
public static void BeginConnect1(string host, int port)
{
IPAddress[] IPs = Dns.GetHostAddresses(host);
Socket s = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
allDone.Reset();
Console.WriteLine("Establishing Connection to {0}",
host);
s.BeginConnect(IPs[0], port,
new AsyncCallback(ConnectCallback1), s);
// wait here until the connect finishes.
// The callback sets allDone.
allDone.WaitOne();
Console.WriteLine("Connection established");
}
示例4: BeginConnect2
// Asynchronous connect, using DNS.GetHostAddresses
public static void BeginConnect2(string host, int port)
{
IPAddress[] IPs = Dns.GetHostAddresses(host);
Socket s = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
allDone.Reset();
Console.WriteLine("Establishing Connection to {0}",
host);
s.BeginConnect(IPs, port,
new AsyncCallback(ConnectCallback1), s);
// wait here until the connect finishes. The callback
// sets allDone.
allDone.WaitOne();
Console.WriteLine("Connection established");
}
示例5: BeginConnect3
// Asynchronous connect using host name (resolved by the
// BeginConnect call.)
public static void BeginConnect3(string host, int port)
{
Socket s = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
allDone.Reset();
Console.WriteLine("Establishing Connection to {0}",
host);
s.BeginConnect(host, port,
new AsyncCallback(ConnectCallback1), s);
// wait here until the connect finishes. The callback
// sets allDone.
allDone.WaitOne();
Console.WriteLine("Connection established");
}