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


C# Sockets.Socket类代码示例

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


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

示例1: AesStream

 public AesStream(Socket socket, EnhancedStream stream, byte[] key)
     : base(socket)
 {
     BaseStream = stream;
     _enc = new CryptoStream(stream, GenerateAES(key).CreateEncryptor(), CryptoStreamMode.Write);
     _dec = new CryptoStream(stream, GenerateAES(key).CreateDecryptor(), CryptoStreamMode.Read);
 }
开发者ID:Valdiralita,项目名称:RawCraft,代码行数:7,代码来源:AesStream.cs

示例2: ClientConnection

 public ClientConnection(Socket socket)
     : base(socket)
 {
     DisconnectedEvent += ClientConnection_DisconnectedEvent;
     m_LittleEndian = true;
     Logger.Trace("Client {0}: Connected", this);
 }
开发者ID:ExpTeam,项目名称:trunk,代码行数:7,代码来源:ClientConnection.cs

示例3: AuthChallenge

        public AuthChallenge(Socket conn)
        {
            int soFar = 0;
            byte[] buffer = new byte[MESSAGE_SIZE];

            while (soFar < MESSAGE_SIZE)
            {
                //read the header and challenge phrase
                int rcvd = conn.Receive(buffer, (int)MESSAGE_SIZE - soFar, SocketFlags.None);
                if (rcvd == 0) throw new AuthException("Disconnect during authentication");
                if (soFar == 0 && buffer[0] != PACKET_IDENTIFIER) throw new AuthException("Invalid challenge packet header");

                //skip the first byte
                if (soFar == 0)
                {
                    if (rcvd > 1) _challenge.Append(buffer, 1, rcvd - 1);
                }
                else
                {
                    _challenge.Append(buffer, 0, rcvd);
                }

                soFar += rcvd;
            }
        }
开发者ID:zwagoth,项目名称:whip-dotnet-client,代码行数:25,代码来源:AuthChallenge.cs

示例4: reConnect

        public void reConnect()
        {
            serviceSocket.Close();
            serviceSocket = null;
            sendBuffer = new byte[1024];//Send buffer //c# automatic assigesd to 0     

            try
            {
                serviceSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                System.Threading.Thread tt = new System.Threading.Thread(delegate()
                {
                    try
                    {
                        serviceSocket.Connect(ip, port);
                    }
                    catch (Exception ee)
                    {
                        //MessageBox.Show(ee.Message + "\r\n From:" + this);
                    }
                });
                tt.Start();

            }
            catch (Exception e)
            {
                //MessageBox.Show(e.Message + "\r\n From:" + this);
            }
        }
开发者ID:Season02,项目名称:MK2.0,代码行数:29,代码来源:socket.cs

示例5: ProcessQueue

 public ProcessQueue(int _cardNo, Player _user, Socket _userSocket, Player _target)
 {
     cardNo = _cardNo;
     user = _user;
     target = _target;
     userSocket = _userSocket;
 }
开发者ID:Ilumia,项目名称:TheVampire_server,代码行数:7,代码来源:RoomInfoProcessing.cs

示例6: AbstractSession

 public AbstractSession(Socket sck)
 {
     this.Actived = false;
     this.Socket = sck;
     this.Handle = sck.Handle.ToInt32();
     this.RemoteEndpoint = sck.RemoteEndPoint.ToString();
 }
开发者ID:robert0609,项目名称:BlueFox,代码行数:7,代码来源:AbstractSession.cs

示例7: initializeConnection

        public bool initializeConnection()
        {
            try
            {
                m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true);

                m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);

                m_socket.SendTimeout = 5000;
                m_socket.ReceiveTimeout = 5000;

                m_frm.Print("Connecting to " + ECCServerIP + " at port " + ECCServerPort + " ...");
                m_socket.Connect(ECCServerIP, Convert.ToInt32(ECCServerPort));
            }
            catch (Exception ex)
            {
                m_frm.Print("Error!Failed to connect to ECC server!" + ex.Message);
                return false;
            }

            if (!Authenticate())
                return false;

            return true;
        }
开发者ID:zacglenn,项目名称:GroupActivityFeed,代码行数:27,代码来源:GroupActivityFeedConnector.cs

示例8: CheckDualModeReceiveSupport

 public static void CheckDualModeReceiveSupport(Socket socket)
 {
     if (!SupportsDualModeIPv4PacketInfo && socket.AddressFamily == AddressFamily.InterNetworkV6 && socket.DualMode)
     {
         throw new PlatformNotSupportedException(SR.net_sockets_dualmode_receivefrom_notsupported);
     }
 }
开发者ID:omariom,项目名称:corefx,代码行数:7,代码来源:SocketPal.Unix.cs

示例9: Dispose

 public void Dispose()
 {
     Socket.Disconnect(false);
     Socket.Shutdown(SocketShutdown.Both);
     Socket.Close();
     Socket = null;
 }
开发者ID:GennadyKharlam,项目名称:TCP-C-Sharp-server,代码行数:7,代码来源:Client.cs

示例10: Client

 public Client(Socket s)
 {
     clientSocket = s;
     //启动一个线程处理客户端的数据接收
     t = new Thread(ReceiveMessage);
     t.Start();
 }
开发者ID:vin120,项目名称:c-shap-code,代码行数:7,代码来源:Client.cs

示例11: OSUserToken

        // The read socket that creates this object sends a copy of its "parent" accept socket in as a reference
        // We also take in a max buffer size for the data to be read off of the read socket
        public OSUserToken(Socket readSocket, Int32 bufferSize, IEFMagLinkRepository repository)
        {
            _repository = repository;
            ownersocket = readSocket;
            stringbuilder = new StringBuilder(bufferSize);

        }
开发者ID:Cocotus,项目名称:High-Performance-.NET-Socket-Server-Using-Async-Winsock,代码行数:9,代码来源:OSUserToken.cs

示例12: AsyncSocketSession

 public AsyncSocketSession(Socket client, SocketAsyncEventArgsProxy socketAsyncProxy, bool isReset)
     : base(client)
 {
     SocketAsyncProxy = socketAsyncProxy;
     m_OrigOffset = socketAsyncProxy.SocketEventArgs.Offset;
     m_IsReset = isReset;
 }
开发者ID:wulinfeng2008,项目名称:SuperSocket,代码行数:7,代码来源:AsyncSocketSession.cs

示例13: WorkerProxy

 public WorkerProxy(NagCoordinator coordinator, Socket socket)
 {
     Worker = new TCPConnection(socket, false, ProcesLine, null);
     NagCoordinator = coordinator;
     State = ConnectionState.Negotiating;
     Negotiate();
 }
开发者ID:tgiphil,项目名称:GoTraxx,代码行数:7,代码来源:WorkerProxy.cs

示例14: Start

        /// <summary>
        /// 启动监听
        /// </summary>
        /// <param name="config">服务器配置</param>
        /// <returns></returns>
        public override bool Start(IServerConfig config)
        {
            m_ListenSocket = new System.Net.Sockets.Socket(this.Info.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                //关联终结地
                m_ListenSocket.Bind(this.Info.EndPoint);
                //设置监听最大连接数
                m_ListenSocket.Listen(m_ListenBackLog);

                m_ListenSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);

                m_ListenSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true);
                //初始化套接字操作
                SocketAsyncEventArgs acceptEventArg = new SocketAsyncEventArgs();
                m_AcceptSAE = acceptEventArg;
                //定义一个连接完成事件
                acceptEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(acceptEventArg_Completed);
                if (!m_ListenSocket.AcceptAsync(acceptEventArg))
                {
                    ProcessAccept(acceptEventArg);
                }
                return true;
            }
            catch (Exception e)
            {
                OnError(e);
                return false;
            }
        }
开发者ID:babywzazy,项目名称:Server,代码行数:36,代码来源:TcpAsyncSocketListener.cs

示例15: OnlineUser

 public OnlineUser(Socket socket, String username, String token, String publicKey)
 {
     WorkSocket = socket;
     Username = username;
     this.token = token;
     PublicKey = publicKey;
 }
开发者ID:fridsamt,项目名称:WordAddIn_Server,代码行数:7,代码来源:OnlineUser.cs


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