当前位置: 首页>>代码示例>>C#>>正文


C# Socket.BeginConnect方法代码示例

本文整理汇总了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());
   }
开发者ID:.NET开发者,项目名称:System.Net.Sockets,代码行数:20,代码来源:Socket.BeginConnect

示例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);
}
开发者ID:.NET开发者,项目名称:System.Net.Sockets,代码行数:12,代码来源:Socket.BeginConnect

示例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");
}
开发者ID:.NET开发者,项目名称:System.Net.Sockets,代码行数:24,代码来源:Socket.BeginConnect

示例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");
}
开发者ID:.NET开发者,项目名称:System.Net.Sockets,代码行数:22,代码来源:Socket.BeginConnect

示例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");
}
开发者ID:.NET开发者,项目名称:System.Net.Sockets,代码行数:21,代码来源:Socket.BeginConnect


注:本文中的System.Net.Sockets.Socket.BeginConnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。