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


C# ISocket.Close方法代码示例

本文整理汇总了C#中ISocket.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ISocket.Close方法的具体用法?C# ISocket.Close怎么用?C# ISocket.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISocket的用法示例。


在下文中一共展示了ISocket.Close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CloseSock

        public static void CloseSock(ISocket socket, int timeout = 0)
        {
            if (socket.GetSocket().ProtocolType == ProtocolType.Tcp) socket.GetSocket().Shutdown(SocketShutdown.Both);

            if (timeout == 0) socket.Close();
            else socket.Close(timeout);
        }
开发者ID:jccprj,项目名称:AwesomeSockets,代码行数:7,代码来源:AweSock.cs

示例2: FindDevices

        public void FindDevices(TimeSpan timeout)
        {
            _socket = _socketFactory.CreateClientSocket();
            var request = _requestFactory.CreateMessage();
            var requestBytes = Encoding.ASCII.GetBytes(request);

            var responseThread = new Thread(GetSearchResponse);
            _socket.SendTo(requestBytes, new IPEndPoint(IPAddress.Parse(Constants.MulticastAddress), Constants.MulticastPort));
            responseThread.Start();
            Thread.Sleep(Convert.ToInt32(timeout.TotalMilliseconds));
            _socket.Close();
        }
开发者ID:estaphorsius,项目名称:devicedisco,代码行数:12,代码来源:DeviceLocator.cs

示例3: OnConnectionAccepted

        private static void OnConnectionAccepted(ISocket client)
        {
            int num = Netplay.FindNextOpenClientSlot();
            if (num != -1)
            {
                Netplay.Clients[num].Socket = client;
                Netplay.Clients[num].sendQueue.StartThread();

                Console.WriteLine(client.GetRemoteAddress() + " is connecting to slot {0}...", num);
            }
            else
            {
                using (var stream = new MemoryStream())
                {
                    using (var writer = new BinaryWriter(stream))
                    {
                        writer.Write((short)0);
                        writer.Write((byte)2);
                        writer.Write("Server is full.");
                        short position = (short)writer.BaseStream.Position;
                        writer.BaseStream.Position = 0L;
                        writer.Write((short)position);
                        byte[] data = stream.ToArray();
                        client.AsyncSend(data, 0, data.Length, delegate { });
                    }
                }
                client.Close();
            }
        }
开发者ID:Celant,项目名称:TerrariaAPI-Server,代码行数:29,代码来源:Netplay.cs

示例4: ProxyThis

 private void ProxyThis(ISocket instream, ISocket outstream, AutoResetEvent readyToConnect)
 {
     Logger.Debug("Starting Proxy from " + instream + " to " + outstream);
     int read = 1;
     Closed = false;
     try
     {
         var inBuffer = new byte[_bufferSize];
         // listen for incoming connection
         if (!instream.Connected)
         {
             readyToConnect.Set();
             Logger.Debug("Listening for incoming connections");
             instream.ListenOnce();
             Logger.Debug("Connected incoming");
         }
         // connect to outgoing endpoint and start the reverse proxy
         if (!outstream.Connected)
         {
             outstream.Connect();
             Logger.Debug("Connected outgoing");
             _outRunner.Start();
             Logger.Debug("Started Reverse Proxy");
         }
         while (read > 0)
         {
             // Read from instream
             if (read > 0)
             {
                 try
                 {
                     read = instream.Read(inBuffer, _bufferSize);
     #if DEBUG
     //                            Logger.Debug("Read " + read + " bytes from " + instream);
     #endif
                 }
                 catch (Exception ex)
                 {
                     Logger.Error("Failed to read data from stream (" + instream + "), closing proxy : " + ex.Message);
                     break;
                 }
                 if (read > 0)
                 {
                     try
                     {
                         outstream.Send(inBuffer, read);
     #if DEBUG
                         //Logger.Debug("Wrote " + read + " bytes to " + outstream);
     #endif
                     }
                     catch (Exception ex)
                     {
                         Logger.Error("Failed to send data through stream (" + instream + ") , closing proxy : " + ex.Message);
                         break;
                     }
                 }
             }
             else
             {
                 Logger.Warn("Read no data from (" + instream + "), closing proxy");
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Error("Thread caught exception while processing : " + ex.Message, ex);
     }
     finally
     {
         try
         {
             instream.Close();
         }
         catch (Exception ex)
         {
             Logger.Error("Caught Error closing stream (" + instream + ") : " + ex.Message, ex);
         }
         try
         {
             outstream.Close();
         }
         catch (Exception ex)
         {
             Logger.Error("Caught Error closing stream (" + outstream + ") : " + ex.Message, ex);
         }
     }
 }
开发者ID:gwupe,项目名称:Gwupe,代码行数:87,代码来源:StreamProxy.cs

示例5: OnDisconnect

 private static void OnDisconnect(ISocket obj)
 {
     obj.Close();
 }
开发者ID:FireflyServer,项目名称:firefly,代码行数:4,代码来源:ServerFactory.cs


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