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


C# Sockets.StateObject类代码示例

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


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

示例1: Start

        public static void Start()
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;

            listener = new Socket(AddressFamily.InterNetwork,
                SocketType.Dgram, ProtocolType.Udp);

            listener.Bind(new IPEndPoint(IPAddress.Any, PORT));

            Console.WriteLine("Waiting for a connection..." + GetLocalIpAddress());

            while (true) {

                EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
                StateObject state = new StateObject();
                state.WorkSocket = listener;
                listener.ReceiveFrom(state.Buffer, ref remoteEndPoint);
                var rawMessage = Encoding.UTF8.GetString(state.Buffer);
                var messages = rawMessage.Split(';');

                if (messages.Length > 1) {
                    var command = messages[0];
                    var deviceName = messages[1];
                    Console.WriteLine("Command is received from Device Name +"+deviceName+"+");
                    string[] portno = remoteEndPoint.ToString().Split(':');
                    Send(portno[1],remoteEndPoint);

                }
            }
        }
开发者ID:ahmeda8,项目名称:audio-youtube-wp7,代码行数:30,代码来源:UdpServer.cs

示例2: Start

        public bool Start()
        {
            if (_started) return true;

            _socket = SocketUtils.OpenSocketConnection("api.triggrapp.com", 9090);

            if (_socket == null)
            {
                _started = false;
                return false;
            }

            _started = true;

            StateObject state = new StateObject();
            state.workSocket = _socket;

            _socket.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);

            SendHandshake();

            StartHeartbeat();

            return true;
        }
开发者ID:artemip,项目名称:triggr-windows,代码行数:25,代码来源:SocketServer.cs

示例3: SyncSocClient

        public SyncSocClient(string _ipAddress, int port, int timeout)
        {

            try
            {
                IPAddress ipAddress = System.Net.IPAddress.Parse(_ipAddress);
                mPort = port;
                remoteEP = new IPEndPoint(ipAddress, mPort);

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

                if (timeout > 0)
                {
                    mSender.ReceiveTimeout = timeout;
                    mSender.SendTimeout = timeout;
                }
                //mSender.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout);

                // The socket will linger for 10 seconds after Socket.Close is called.
                LingerOption lingerOption = new LingerOption(true, 10);

                mSender.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);

                stateObj = new StateObject(mSender);
            }
            catch (Exception e)
            {
                SetErrorMessage(e, string.Format("소켓생성Error ip[{0}]/port[{1}]/timeout[{2}]]",_ipAddress,port,timeout));
                Logger.error(e.ToString());
            }
        }
开发者ID:WeDoCrm,项目名称:WeDoServer2.0,代码行数:32,代码来源:SocketClient.cs

示例4: Connect

        private bool Connect(StateObject stateObject) {
            Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(hostIp), hostPort);

            stateObject.workSocket = client;

            int retry = retryTime;
            while (true) {
                try {
                    // Connect to the remote endpoint.
                    client.Connect(ipEndPoint);
                    break;
                } catch (Exception be) {
                    retry--;
                    Logging.LogError(be.Message);
                    Logging.LogError("Retry time: " + retry);
                }
                if (retry <= 0) {
                    Logging.LogError("Connecntion Error.");
                    return false;
                }
            }

            client.SendTimeout = timeout;
            client.ReceiveTimeout = timeout;

            return true;
        }
开发者ID:jxqlovejava,项目名称:Tatala-RPC,代码行数:28,代码来源:ShortClientSession.cs

示例5: start

        public Object start(TransferObject to) {
            Object resultObject = null;

            String calleeClass = to.getCalleeClass();
            String calleeMethod = to.getCalleeMethod();

            StateObject stateObject = new StateObject();
            stateObject.transferObject = to;

            try {
                if (Connect(stateObject)) {

                    Send(stateObject);

                    resultObject = Receive(stateObject);
                }
            } catch (Exception e) {
                Logging.LogError("Callee Class and Method: [" + calleeClass + "." + calleeMethod + "]");
                Logging.LogError(e.ToString());
            } finally {
                Close(stateObject);
            }

            return resultObject;
        }
开发者ID:jxqlovejava,项目名称:Tatala-RPC,代码行数:25,代码来源:ShortClientSession.cs

示例6: Connection

        public Connection(Server server, Socket socket)
        {
            m_Server = server;
            m_Socket = socket;

            var state = new StateObject { Socket = m_Socket };
            m_Socket.BeginReceive(state.Buffer, 0, StateObject.BufferSize, SocketFlags.None, ReceiveCallback, state);
        }
开发者ID:miceiken,项目名称:WoWClassicAuthServer,代码行数:8,代码来源:Connection.cs

示例7: ReadMessage

 public string ReadMessage(Socket client)
 {
     StateObject state = new StateObject();
     state.workSocket = client;
     client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);
     readDone.WaitOne();
     readDone.Reset();
     return state.sb.ToString();
 }
开发者ID:vit2005,项目名称:Multitier-Project,代码行数:9,代码来源:Messager.cs

示例8: AcceptCallback

        public void AcceptCallback(IAsyncResult ar)
        {
            // Get the socket that handles the client request.
            Socket listener = (Socket)ar.AsyncState;
            Socket handler = listener.EndAccept(ar);

            // Create the state object.
            StateObject state = new StateObject();
            state.workSocket = handler;
            AskForReceive(handler, state);
        }
开发者ID:raanand-home,项目名称:MotherSync,代码行数:11,代码来源:ServerTcp.cs

示例9: BeginConnect

        IAsyncResult BeginConnect(AsyncCallback requestCallback, object userToken)
        {
            var stateObject = new StateObject()
            {
                AsyncState = userToken,
                Callback = requestCallback,
                IsCompleted = false
            };

            this.ConnectAsync(stateObject);
            return stateObject;
        }
开发者ID:btyouth,项目名称:EpServerEngine.cs,代码行数:12,代码来源:TcpClient.cs

示例10: StartReceiving

        public void StartReceiving()
        {
            if (OnNotifyMulticastSocketListener == null)
            throw new ApplicationException("No socket listener has been specified at OnNotifyMulticastSocketListener.");

              // Create the state object.
              StateObject state = new StateObject();
              state.WorkSocket = udpSocket;

              //get in waiting mode for data - always (this doesn't halt code execution)
              Recieve(state);
        }
开发者ID:hcilab-um,项目名称:tPad,代码行数:12,代码来源:MulticastSocket.cs

示例11: DoWork

 // Method passed to ThreadStart.
 //
 // This is the thread's starting point. It starts the process on the server machine, creates three ``state objects'', which will
 // help us handle the redirections asynchronously. We associate the BeginRead methods of the standard output and error streams
 // with our call-back (LocalReadCallback), to start processing the output of the command. We also associate the BeginRead() method
 // the socket to our socket read call-back (ReadCallback), so we can process the data received through the socket.
 public void DoWork()
 {
     Process process = Process.Start(_processStartInfo);
         LocalStateObject outputLocalStateObject = new LocalStateObject(_socket, process, process.StandardOutput.BaseStream);
         process.StandardOutput.BaseStream.BeginRead(outputLocalStateObject.Buffer, 0, LocalStateObject.BUFFER_SIZE, new AsyncCallback(LocalReadCallback), outputLocalStateObject);
         LocalStateObject errorLocalStateObject = new LocalStateObject(_socket, process, process.StandardError.BaseStream);
         process.StandardError.BaseStream.BeginRead(errorLocalStateObject.Buffer, 0, LocalStateObject.BUFFER_SIZE, new AsyncCallback(LocalReadCallback), errorLocalStateObject);
         StateObject stateObject = new StateObject(_socket, process);
         _socket.BeginReceive(stateObject.Buffer, 0, StateObject.BUFFER_SIZE, 0, new AsyncCallback(ReadCallback), stateObject);
         process.WaitForExit();
         _socket.Close();
 }
开发者ID:dualbus,项目名称:CsTelnetd,代码行数:18,代码来源:Program.cs

示例12: AcceptCallback

            public static void AcceptCallback(IAsyncResult ar)
            {
                allDone.Set();

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

                StateObject state = new StateObject();
                state.workSocket = handler;
                handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                    new AsyncCallback(ReadCallback), state);
            }
开发者ID:RoykoSerhiy,项目名称:visualStudio_projects,代码行数:12,代码来源:MainWindow.xaml.cs

示例13: ConnectAsync

 void ConnectAsync(StateObject stateObject)
 {
     var e = new SocketAsyncEventArgs();
     e.UserToken = stateObject;
     e.RemoteEndPoint = _endpoint;
     e.Completed += OnConnectedAsync;
     try
     {
         this.Client.ConnectAsync(e);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message + " >" + ex.StackTrace);
     }
 }
开发者ID:btyouth,项目名称:EpServerEngine.cs,代码行数:15,代码来源:TcpClient.cs

示例14: AcceptCallback

        public void AcceptCallback(IAsyncResult ar)
        {

            allDone.Set();


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


            StateObject state = new StateObject();
            state.workSocket = handler;
            handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, SocketFlags.None, ReadCallbackFileRecive, state);
            flag = 0;
        }
开发者ID:zlphoenix,项目名称:LearnCSharp,代码行数:15,代码来源:Server.cs

示例15: AcceptCallback

        public static void AcceptCallback(IAsyncResult ar)
        {
            // Signal the main thread to continue.
            allDone.Set();

            // Get the socket that handles the client request.
            Socket listener = (Socket)ar.AsyncState;
            Socket handler = listener.EndAccept(ar);

            // Create the state object.
            StateObject state = new StateObject();
            state.workSocket = handler;
            handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                new AsyncCallback(ReadCallback), state);
        }
开发者ID:sonrac,项目名称:wincc_tags_parser,代码行数:15,代码来源:AsynchronousSocketListener.cs


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