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


C# Socket.GetHashCode方法代码示例

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


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

示例1: NetworkConnection

        public NetworkConnection( Socket socket )
        {
            Contract.Requires( socket != null );
            Logger = new DefaultSessionLogger();
            Logger.Verbose( string.Format( "{0} NetworkConnection Constructor", socket.GetHashCode() ) );

            _socket = socket;

            _hasClosed = false;
            _hasShutdown = false;
        }
开发者ID:williamoneill,项目名称:Gallatin,代码行数:11,代码来源:NetworkConnection.cs

示例2: Client

        public Client(Socket workerSocket)
        {
            Status = Client.ConnectionState.Waiting;
            socket = workerSocket;
            hash = socket.GetHashCode();

            FirstByte = new byte[1];
            LastByte = new byte[1];
            FirstByte[0] = 0x00;
            LastByte[0] = 0xFF;

            this.Established += HandleEstablished;
            this.Authenticated += HandleAuthenticated;
            waitForData();
        }
开发者ID:seratonik,项目名称:CSharp-Websockets-MUD-Server,代码行数:15,代码来源:Client.cs

示例3: GetHashCodeTest

		public void GetHashCodeTest ()
		{
			Socket server = new Socket (AddressFamily.InterNetwork,
				SocketType.Stream, ProtocolType.Tcp);
			IPEndPoint ep = new IPEndPoint (IPAddress.Loopback,
							9010);
			server.Bind (ep);
			server.Listen (1);

			Socket client = new Socket (AddressFamily.InterNetwork, 
				SocketType.Stream, ProtocolType.Tcp);
			int hashcodeA = client.GetHashCode ();
			client.Connect (ep);
			int hashcodeB = client.GetHashCode ();
			Assert.AreEqual (hashcodeA, hashcodeB, "#1");
			client.Close ();
			int hashcodeC = client.GetHashCode ();
			Assert.AreEqual (hashcodeB, hashcodeC, "#2");
			server.Close ();
		}
开发者ID:Therzok,项目名称:mono,代码行数:20,代码来源:SocketTest.cs

示例4: SetUnicastReusePortForSocket

        /// <summary>
        ///    <para>Set SocketOptionName.ReuseUnicastPort (SO_REUSE_UNICASTPORT) socket option on the outbound connection.</para>
        /// </summary>
        private void SetUnicastReusePortForSocket(Socket socket)
        {
            bool reusePort;
         
            if (ServicePointManager.ReusePortSupported.HasValue && !ServicePointManager.ReusePortSupported.Value) {
                // We tried to set the socket option before and it isn't supported on this system.  So, we'll save some
                // time by not trying again.
                reusePort = false;
            }
            else {
                reusePort = ServicePointManager.ReusePort;
            }

            if (reusePort) {
                // This socket option is defined in Windows 10.0 or later.  It is also
                // available if an LDR servicing patch has been installed on downlevel OS.
                try {
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseUnicastPort, 0x1);
                    if (Logging.On) { 
                        Logging.PrintInfo(Logging.Web, this, SR.GetString(SR.net_log_set_socketoption_reuseport, 
                            "Socket", socket.GetHashCode()));
                    }
                    
                    ServicePointManager.ReusePortSupported = true;
                }
                catch (SocketException) {
                    // The socket option is not supported.  We will ignore this error and fail gracefully.
                    if (Logging.On) { 
                        Logging.PrintInfo(Logging.Web, this, SR.GetString(SR.net_log_set_socketoption_reuseport_not_supported, 
                            "Socket", socket.GetHashCode()));
                    }                    
                    ServicePointManager.ReusePortSupported = false;
                }
                catch (Exception ex) {
                    // We want to preserve app compat and trap any other unusual exceptions.
                    if (Logging.On) { 
                        Logging.PrintInfo(Logging.Web, this, SR.GetString(SR.net_log_unexpected_exception, ex.Message));
                    }
                }
            }            
        }
开发者ID:uQr,项目名称:referencesource,代码行数:44,代码来源:ServicePoint.cs

示例5: ConnectAsync

        public void ConnectAsync()
        {
            SocketAsyncEventArgs socketArgs;

            try
            {
                _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                Logger.Network.Debug("Socket ID: " + _socket.GetHashCode().ToString() + "\r\nSocket created.");
            }
            catch (Exception e)
            {
                Logger.Network.Error("Socket ID: " + _socket.GetHashCode().ToString() + "\r\nAn exception occurred while instantiating the socket.", e);
                if (OnError != null)
                {
                    OnError(this, "Exception instantiating socket.", e);
                    return;
                }
                else throw;
            }

            try
            {
                _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, SendBufferSettings.Timeout);
                _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, ReceiveBufferSettings.Timeout);
                _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, SendBufferSettings.Size);
                _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, ReceiveBufferSettings.Size);
            }
            catch (Exception e)
            {
                Logger.Network.Error("Socket ID: " + _socket.GetHashCode().ToString() + "\r\nAn exception occurred while settings socket options.", e);
                if (OnError != null)
                {
                    OnError(this, "Exception settings socket options.", e);
                    return;
                }
                else throw;
            }

            lock (_socket)
            {
                socketArgs = new SocketAsyncEventArgs()
                {
                    RemoteEndPoint = EndPoint
                };
                socketArgs.Completed += new EventHandler<SocketAsyncEventArgs>(Connect_Completed);
                socketArgs.UserToken = new TcpConnectionAsyncEventArgs(new Timeout(SendBufferSettings.Timeout, Connect_Timeout));

                Logger.Network.Debug("Socket ID: " + _socket.GetHashCode().ToString() + "\r\nConnecting to " + EndPoint.Address.ToString() + " on " + EndPoint.Port.ToString() + "...");

                try
                {
                    if (!_socket.ConnectAsync(socketArgs))
                    {
                        Logger.Network.Debug("Socket ID: " + _socket.GetHashCode().ToString() + "\r\nConnectAsync completed synchronously.");
                        Connect_Completed(null, socketArgs);
                    }
                }
                catch (Exception e)
                {
                    Logger.Network.Error("Socket ID: " + _socket.GetHashCode().ToString() + "\r\nAn exception occurred while connecting the socket.", e);
                    if (OnError != null) OnError(this, "Exception connecting socket.", e);
                    else throw;
                }
            }
        }
开发者ID:274706834,项目名称:opendms-dot-net,代码行数:65,代码来源:TcpConnection.cs

示例6: ProccessCommandCustom

		private void ProccessCommandCustom(BaseCommand command, Socket socket)
		{
			RenewSessionState(socket);
			if (OnCustomCommand != null)
			{
				OnCustomCommand(this, new CustomCommandEventArgs
				{
					Command = command,
					SessionId = socket.GetHashCode()
				});
			}
		}
开发者ID:shenzhigang,项目名称:ZSocket,代码行数:12,代码来源:ZSocketServer.cs

示例7: ProccessCommandRegist

		private void ProccessCommandRegist(CmdRegist cmdRegist, Socket socket)
		{
			RenewSessionState(socket);
			var sessionId = socket.GetHashCode();
			if (OnNewSession != null)
			{
				OnNewSession(this, new NewSessionEventArgs
				{
					PrevSessionId = cmdRegist.PrevSessionId,
					SessionId = sessionId
				});
			}
			Send(socket, new CmdRegistResp {
				 SessionId = sessionId
			});
		}
开发者ID:shenzhigang,项目名称:ZSocket,代码行数:16,代码来源:ZSocketServer.cs

示例8: RenewSessionState

		private void RenewSessionState(Socket socket,bool registed= true) {
			int sessionId = socket.GetHashCode();
			rwlForSessionStateDict.AcquireReaderLock(int.MaxValue);
			try
			{
				if (sessionStateDict.ContainsKey(sessionId)) {
					var ss = sessionStateDict[sessionId];
					if (socket != ss.Socket)
						throw new Exception("socket not match");
					ss.LastRespondTime = DateTime.Now;
					ss.Registed = registed;
				}
			}
			catch (Exception)
			{

				throw;
			}
			finally
			{
				rwlForSessionStateDict.ReleaseReaderLock();
			}
		}
开发者ID:shenzhigang,项目名称:ZSocket,代码行数:23,代码来源:ZSocketServer.cs

示例9: ProcessNewConnection

		private void ProcessNewConnection(Socket socket)
		{
			int sessionId = socket.GetHashCode();
			SessionState ss = new SessionState
			{
				Socket = socket,
				LastRespondTime = DateTime.Now,
				Registed = false,
				SessionId = sessionId
			};

			rwlForSessionStateDict.AcquireWriterLock(int.MaxValue);
			try
			{
				if (!sessionStateDict.ContainsKey(sessionId))
				{
					sessionStateDict.Add(sessionId, ss);
				}
				else {
					sessionStateDict[sessionId] = ss;
				}
			}
			catch (Exception)
			{
				throw;
			}
			finally
			{
				rwlForSessionStateDict.ReleaseWriterLock();
			}

		}
开发者ID:shenzhigang,项目名称:ZSocket,代码行数:32,代码来源:ZSocketServer.cs


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