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


C# SocketState类代码示例

本文整理汇总了C#中SocketState的典型用法代码示例。如果您正苦于以下问题:C# SocketState类的具体用法?C# SocketState怎么用?C# SocketState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: SocketStream

        public SocketStream(SocketInfo info, IOLoop ioloop)
            : base(ioloop)
        {
            state = SocketState.Open;

            port = info.port;
            address = info.Address;
        }
开发者ID:aaronfeng,项目名称:manos,代码行数:8,代码来源:SocketStream.cs

示例2: Client

    // --

    public Client(IClientListener listener)
    {
        this.listeners = new List<IClientListener>();
        this.listeners.Add(listener);
        this.username = User.Instance.username;
        this.id = User.Instance.id;
        this.state = SocketState.DISCONNECTED;
    }
开发者ID:CanPayU,项目名称:SuperSwungBall,代码行数:10,代码来源:Client.cs

示例3: SocketStream

        public SocketStream(Socket socket, IOLoop ioloop)
            : base(ioloop)
        {
            this.socket = socket;

            if (socket != null) {
                socket.Blocking = false;
                SetHandle (IOWatcher.GetHandle (socket));
                state = SocketState.Open;
            }
        }
开发者ID:koush,项目名称:manos,代码行数:11,代码来源:SocketStream.cs

示例4: SocketStream

        public SocketStream(SocketInfo info, IOLoop ioloop)
            : base(ioloop)
        {
            fd = info.fd;

            if (fd > 0) {
                SetHandle (fd);
                state = SocketState.Open;
            }

            port = info.port;
        }
开发者ID:axelc,项目名称:manos,代码行数:12,代码来源:SocketStream.cs

示例5: CloseAbortively

 public void CloseAbortively()
 {
     try
     {
         ClientSocket.AbortiveClose();
         ClientSocket = null;
         ClientSocketState = SocketState.Closed;
         Console.WriteLine("Abortively closed socket");
     }
     catch (Exception ex)
     {
         ResetSocket();
         Console.WriteLine("Error aborting socket: [" + ex.GetType().Name + "] " + ex.Message);
     }
     finally
     {
         RefreshDisplay();
     }
 }
开发者ID:cosmo1911,项目名称:UniMoveStation,代码行数:19,代码来源:NitoClient.cs

示例6: Connect

    /// <summary>
    /// Connexion au serveur
    /// </summary>
    /// <param name="host">Localisation du serveur</param>
    /// <param name="port">Id of friend</param>
    /// <param name="authenticate">Authentification automatique</param>
    public void Connect(string host = HOST, int port = PORT, bool authenticate = true)
    {
        this._sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        try
        {
            _sock.Connect(host, port);
            this.state = SocketState.CONNECTED;

            run = new Thread(new ThreadStart(ReceiveLoop));
            run.Name = "ReceiveThread";
            run.IsBackground = true;
            run.Start();

            if (authenticate)
                this.Authenticate();
        }
        catch (Exception e)
        {
            Debug.Log("Erreur de connexion : " + e.Message);
        }
    }
开发者ID:CanPayU,项目名称:SuperSwungBall,代码行数:27,代码来源:Client.cs

示例7: SendToClient

        private void SendToClient(SocketState state, byte[] data)
        {
            if (state == null)
                return;

            if (state.Socket == null || !state.Socket.Connected) {
                state.Dispose();
                state = null;
                return;
            }

            if (_socketSendCallback == null)
                _socketSendCallback = OnSent;

            try {
                state.Socket.BeginSend(data, 0, data.Length, SocketFlags.None, _socketSendCallback, state);
            } catch (SocketException e) {
                LogError(Category, "Error sending data");
                LogError(Category, String.Format("{0} {1}", e.SocketErrorCode, e));
            }
        }
开发者ID:IPA-ZONE,项目名称:PRMasterServer,代码行数:21,代码来源:ServerListRetrieve.cs

示例8: AcceptCallback

        private void AcceptCallback(IAsyncResult ar)
        {
            _reset.Set();

            Socket listener = (Socket)ar.AsyncState;
            Socket handler = listener.EndAccept(ar);

            SocketState state = new SocketState() {
                Socket = handler
            };

            WaitForData(state);
        }
开发者ID:IPA-ZONE,项目名称:PRMasterServer,代码行数:13,代码来源:ServerListRetrieve.cs

示例9: SendRemainingBytes

        private void SendRemainingBytes(int offset, int count)
        {
            lock (this)
            {
                if (socketState == SocketState.Idle)
                {
                    socketState = SocketState.Sending;

                    this.eventArgs.SetBuffer(offset, count);
                    bool asynchronous = this.socket.SendAsync(this.eventArgs);
                    if (!asynchronous)
                    {
                        this.IOCompleted(this, this.eventArgs);
                    }
                }
                else
                {
                    Console.WriteLine("Error: we shouldn't have come here 2");
                }
            }
        }
开发者ID:smosgin,项目名称:labofthings,代码行数:21,代码来源:ServiceConnection.cs

示例10: TrySend

        private void TrySend()
        {
            lock (this)
            {
                if (socketState == SocketState.Idle)
                {
                    var messageToSend = outgoingMessages.Dequeue();

                    socketState = SocketState.Sending;

                    this.eventArgs.SetBuffer(messageToSend, 0, messageToSend.Length);
                    bool asynchronous = this.socket.SendAsync(this.eventArgs);
                    if (!asynchronous)
                    {
                        this.IOCompleted(this, this.eventArgs);
                    }
                }
            }
        }
开发者ID:smosgin,项目名称:labofthings,代码行数:19,代码来源:ServiceConnection.cs

示例11: beginAcceptCallback_forStartListening

          private void beginAcceptCallback_forStartListening(IAsyncResult result)
          {
                  Console.WriteLine("TransportLayerCommunicator::beginAcceptCallback_forStartListening ENTER");
          
      SocketUtility.SocketListener.SocketListenState socketListenState = (SocketUtility.SocketListener.SocketListenState) result.AsyncState;
      // Signal the listener thread to continue.
      socketListenState.allDone.Set();
      Socket listener = socketListenState.sock;
      Socket handler = listener.EndAccept(result);
        
      TransportLayerCommunicator transportLayerCommunicator = (TransportLayerCommunicator)(socketListenState.obj);
                 
          SockMsgQueue sockMsgQueue = new SockMsgQueue(handler, transportLayerCommunicator );
          IPAddress IP = ((IPEndPoint)(handler.RemoteEndPoint)).Address;
          SocketState socketState = new SocketState();
          socketState.transportLayerCommunicator = transportLayerCommunicator;
                     
          try
                  {
                          transportLayerCommunicator.commRegistry.Add(IP, sockMsgQueue);
                          socketState.sock = handler;
                  handler.BeginReceive( socketState.buffer, 0, socketState.buffer.Length, new SocketFlags(), new AsyncCallback(beginReceiveCallBack), socketState);      
                          Console.WriteLine("TransportLayerCommunicator::beginAcceptCallback_forStartListening EXIT");
          }
                  catch(System.ArgumentException)
                  {
                          socketState.sock = handler;
                  handler.BeginReceive( socketState.buffer, 0, socketState.buffer.Length, new SocketFlags(), new AsyncCallback(beginReceiveCallBack), socketState);      
                  Console.WriteLine("TransportLayerCommunicator::beginAcceptCallback_forStartListening EXIT");
                  }
                  Console.WriteLine("TransportLayerCommunicator::beginAcceptCallback_forStartListening EXIT");
 
          }
开发者ID:ratulmukh,项目名称:tashjik,代码行数:33,代码来源:TransportLayerCommunicator.cs

示例12: OnChangeState

		protected void OnChangeState(SocketState newState)
		{
			SocketState prev = this.state;
			this.state = newState;
			if (this.StateChanged != null)
				this.StateChanged(new NetSockStateChangedEventArgs(this.state, prev));

			if (this.state == SocketState.Connected)
				this.connectionTimer.Change(0, this.ConnectionCheckInterval);
			else if (this.state == SocketState.Closed)
				this.connectionTimer.Change(Timeout.Infinite, Timeout.Infinite);
		}
开发者ID:fuutou89,项目名称:AngeVierge,代码行数:12,代码来源:NetSocket.cs

示例13: Close

        /// <summary>
        /// Close the socket.  This is NOT async.  .Net doesn't have
        /// async closes.  But, it can be *called* async, particularly
        /// from GotData.  Attempts to do a shutdown() first.
        /// </summary>
        public override void Close()
        {
            Debug.WriteLine("Close");
            lock (this)
            {
                /*
                switch (State)
                {
                case State.Closed:
                    throw new InvalidOperationException("Socket already closed");
                case State.Closing:
                    throw new InvalidOperationException("Socket already closing");
                }
                */

                SocketState oldState = State;

                if (m_sock.Connected)
                {
                    State = SocketState.Closing;
                }

                if (m_stream != null)
                    m_stream.Close();
                else
                {
                    try
                    {
                        m_sock.Close();
                    }
                    catch { }
                }

                if (oldState <= SocketState.Connected)
                    m_listener.OnClose(this);

                if (m_watcher != null)
                    m_watcher.CleanupSocket(this);

                State = SocketState.Closed;
            }
        }
开发者ID:oli-obk,项目名称:jabber-net,代码行数:47,代码来源:AsyncSocket.cs

示例14: Accept

        /// <summary>
        /// Prepare to start accepting inbound requests.  Call
        /// RequestAccept() to start the async process.
        /// </summary>
        /// <param name="addr">Address to listen on</param>
        /// <param name="backlog">The Maximum length of the queue of
        /// pending connections</param>
        public override void Accept(Address addr, int backlog)
        {
            lock (this)
            {
                m_addr = addr;

                m_sock = new Socket(AddressFamily.InterNetwork,
                                    SocketType.Stream,
                                    ProtocolType.Tcp);

                // Always reuse address.
                m_sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
                m_sock.Bind(m_addr.Endpoint);
                m_sock.Listen(backlog);
                State = SocketState.Listening;

                if (m_watcher != null)
                    m_watcher.RegisterSocket(this);
            }
        }
开发者ID:oli-obk,项目名称:jabber-net,代码行数:27,代码来源:AsyncSocket.cs

示例15: OnConnectResolved

        /// <summary>
        /// Address resolution finished.  Try connecting.
        /// </summary>
        /// <param name="addr"></param>
        private void OnConnectResolved(Address addr)
        {
            // Debug.WriteLine("connectresolved: " + addr.ToString());
            lock (this)
            {
                if (State != SocketState.Resolving)
                {
                    // closed in the mean time.   Probably not an error.
                    return;
                }
                if ((addr == null) || (addr.IP == null) || (addr.Endpoint == null))
                {
                    FireError(new AsyncSocketConnectionException("Bad host: " + addr.Hostname));
                    return;
                }

                if (m_watcher != null)
                    m_watcher.RegisterSocket(this);

                m_addr = addr;
                State = SocketState.Connecting;

                if (Socket.OSSupportsIPv6 && (m_addr.Endpoint.AddressFamily == AddressFamily.InterNetworkV6))
                {
                    // Debug.WriteLine("ipv6");
                    m_sock = new Socket(AddressFamily.InterNetworkV6,
                        SocketType.Stream,
                        ProtocolType.Tcp);
                }
                else
                {
                    // Debug.WriteLine("ipv4");
                    m_sock = new Socket(AddressFamily.InterNetwork,
                        SocketType.Stream,
                        ProtocolType.Tcp);
                }

                // well, of course this isn't right.
                m_sock.SetSocketOption(SocketOptionLevel.Socket,
                    SocketOptionName.ReceiveBuffer,
                    4 * m_buf.Length);
            }

            if (m_synch)
            {
                try
                {
                    m_sock.Connect(m_addr.Endpoint);
                }
                catch (SocketException ex)
                {
                    FireError(ex);
                    return;
                }

                if (m_sock.Connected)
                {
                    // TODO: check to see if this Mono bug is still valid
            #if __MonoCS__
                    m_sock.Blocking = true;
                    m_stream = new NetworkStream(m_sock);
                    m_sock.Blocking = false;
            #else
                    m_stream = new NetworkStream(m_sock);
            #endif
                    if (m_secureProtocol != SslProtocols.None)
                        StartTLS();

                    lock (this)
                    {
                        State = SocketState.Connected;
                    }
                    m_listener.OnConnect(this);
                }
                else
                {
                    AsyncClose();
                    FireError(new AsyncSocketConnectionException("could not connect"));
                }
            }
            else
            {
            #if __MonoCS__
                m_sock.Blocking = false;
            #endif
                m_sock.BeginConnect(m_addr.Endpoint, new AsyncCallback(ExecuteConnect), null);
            }
        }
开发者ID:oli-obk,项目名称:jabber-net,代码行数:92,代码来源:AsyncSocket.cs


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