示例#1
0
        public void Serve(ushort port, LuaFunction onConnected, LuaFunction onRecv)
        {
            this.onConnected = onConnected.Retain();
            this.onRecv      = onRecv.Retain();
            TcpIpServer.Serve(port, OnConnected);

#if UNITY_EDITOR
            var x      = 100;
            var y      = 60;
            var width  = 200;
            var height = 80;
            DBG_AddGraph_Native(
                "server_send", "kbps", GetSendBandwidth, 10, 0.5f,
                x, y, width, height, Color.red);

            y += height + 5;
            DBG_AddGraph_Native(
                "server_recv", "kbps", GetRecvBandwidth, 10, 0.5f,
                x, y, width, height, Color.blue);

            y += height + 5;
            DBG_AddGraph_Native(
                "proxy_send", "kbps", GetProxySendBandwidth, 10, 0.5f,
                x, y, width, height, Color.red);

            y += height + 5;
            DBG_AddGraph_Native(
                "proxy_recv", "kbps", GetProxyRecvBandwidth, 10, 0.5f,
                x, y, width, height, Color.blue);
#endif
        }
示例#2
0
        protected override void OnDestroy()
        {
            if (onProxyConnected != null)
            {
                onProxyConnected.Dispose();
                onProxyConnected = null;
            }
            if (onProxyRecv != null)
            {
                onProxyRecv.Dispose();
                onProxyRecv = null;
            }
            if (proxyClient != null)
            {
                proxyClient.Close();
                proxyClient = null;
            }
            if (onConnected != null)
            {
                onConnected.Dispose();
                onConnected = null;
            }
            if (onRecv != null)
            {
                onRecv.Dispose();
                onRecv = null;
            }
            TcpIpServer.Shutdown();

            base.OnDestroy();
        }
        public void ProcMessage()
        {
            TcpClient client = TcpIpServer.GetInClient();

            if (client == null)
            {
                client = TcpIpServer.GetOutClient();
            }
            else
            {
                client = TcpIpServer.GetInClient();
            }
            Console.WriteLine("입고 로봇 :{0}", ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString());
            Console.WriteLine();

            NetworkStream stream = client.GetStream();

            int    length;
            string data = null;

            byte[] bytes = new byte[256];

            while ((length = stream.Read(bytes, 0, bytes.Length)) != 0)
            {
                data = Encoding.Default.GetString(bytes, 0, length);
                Console.WriteLine(String.Format("수신 : {0}", data));

                byte[] msg = Encoding.Default.GetBytes(data);
                stream.Write(msg, 0, msg.Length);
                Console.WriteLine(String.Format("송신: {0}", data));
            }
            stream.Close();
            client.Close();
        }
    /*private RectTransform guiRectTransformNeutral;
     * private RectTransform guiRectTransformAngry;
     * private RectTransform guiRectTransformAstonichment;
     * private RectTransform guiRectTransformHappy;*/

    // Use this for initialization
    void Start()
    {
        tcp_server = new TcpIpServer("0.0.0.0", ServerPort);

        /*this.guiRectTransformNeutral = Neutral.GetComponent<RectTransform>();
         * this.guiRectTransformAngry = Angry.GetComponent<RectTransform>();
         * this.guiRectTransformAstonichment = Astonichment.GetComponent<RectT*/
    }
示例#5
0
 // Use this for initialization
 void Start()
 {
     Application.runInBackground = true;
     // Create TCP Server and Block until Client is connected
     tcpServer = new TcpIpServer("0.0.0.0", serverPort);
     // VideoPlayer component from Screen
     videoPlayer = screen.GetComponent <UnityEngine.Video.VideoPlayer>();
 }
示例#6
0
        //初始化
        private void init(int tcpListenPort)
        {
            _connectedClientList = new List <Socket>();
            this.SetRequestHandlerMap(new Dictionary <String, AbstractRequestHandler>());
            this._tcpListenPort        = tcpListenPort;
            _tcpIpServer               = new TcpIpServer();
            _tcpIpServer.TcpListenPort = tcpListenPort;
            _tcpIpServer.ReadTimeOut   = _heartBeatTimeout * 1000;
            _tcpIpServer.WriteTimeOut  = _heartBeatTimeout * 1000;

            //添加事件绑定
            _tcpIpServer.NewTcpConnected += new EventHandler <NewTcpConnectedArgs>(tcpIpServer_NewTcpConnected);
        }
示例#7
0
        private void init(String rootFolderPath, IPAddress ipAddress, Int32 port)
        {
            this.RootFolderPath          = rootFolderPath;
            this.ipAddress               = ipAddress;
            tcpIpServer                  = new TcpIpServer();
            tcpIpServer.IPAddress        = IPAddress;
            tcpIpServer.TcpListenPort    = port;
            tcpIpServer.NewTcpConnected += new EventHandler <Base.EventArgs.NewTcpConnectedArgs>(tcpIpServer_NewTcpConnected);

            Assembly assembly = Assembly.GetExecutingAssembly();

            CopyRight          = String.Format("<p style=\"color:#C0C0C0;font-family:黑体;font-size:8;text-align:center;\">Powered by {0}/{1} ,<a href=\"http://www.scbeta.com\">作者网站</a>&nbsp;<a href=\"mailto:[email protected]\">作者邮箱</a></p>", this.GetType().FullName, assembly.GetName().Version);
            folderPngByteArray = Convert.FromBase64String(folderPngBase64String);
            filePngByteArray   = Convert.FromBase64String(filePngBase64String);
            init_mime();
        }
    // Use this for initialization
    void Start()
    {
        // Create TCP Server and Block until Client is connected
        tcp_server   = new TcpIpServer("0.0.0.0", ServerPort);
        video1Player = video1.GetComponent <UnityEngine.Video.VideoPlayer>();
        video2Player = video2.GetComponent <UnityEngine.Video.VideoPlayer>();
        video3Player = video3.GetComponent <UnityEngine.Video.VideoPlayer>();
        video4Player = video4.GetComponent <UnityEngine.Video.VideoPlayer>();
        video5Player = video5.GetComponent <UnityEngine.Video.VideoPlayer>();
        video6Player = video6.GetComponent <UnityEngine.Video.VideoPlayer>();

        video1Player.Prepare();
        video2Player.Prepare();
        video3Player.Prepare();
        video4Player.Prepare();
        video5Player.Prepare();
        video6Player.Prepare();
    }
 // Use this for initialization
 void Start()
 {
     // Create TCP Server and Block until Client is connected
     tcp_server = new TcpIpServer("0.0.0.0", ServerPort);
 }
示例#10
0
 // Use this for initialization
 void Start()
 {
     // Create TCP Server and Block until Client is connected
     tcp_server            = new TcpIpServer("0.0.0.0", ServerPort);
     this.guiRectTransform = gazeTarget.GetComponent <RectTransform>();
 }
示例#11
0
        public Task StartAsync(int port)
        {
            startCancellationTokenSource = new CancellationTokenSource();
            CancellationToken cancellationToken = startCancellationTokenSource.Token;
            IPEndPoint        localEndPoint     = new IPEndPoint(IPAddress.Any, port);

            return(Task.Run(() =>
            {
                try
                {
                    using (server = new TcpIpServer(localEndPoint, localEndPoint.AddressFamily, Preferences.ServerStringEncoding, Preferences.ReceiveTimeout, Preferences.SendTimeout, TcpIpServer.DEF_LISTENER_QUEUE_SIZE, TcpIpServer.DEF_RECEIVE_BUFFER_SIZE))
                    {
                        displayedLocalEndPoint = new IPEndPoint(TcpIp.Helper.GetHostIpAsync(Dns.GetHostName()).Result, port);
                        server.Listen();
                        stateReporter.Report("Server started at " + LocalEndPoint + ".");

                        while (!cancellationToken.IsCancellationRequested)
                        {
                            server.AcceptSocket();
                            stateReporter.Report("Connected to " + server.RemoteEndPoint + ".");

                            lastRequestString = string.Empty;

                            while (!cancellationToken.IsCancellationRequested)
                            {
                                try
                                {
                                    lastRequestString = server.Receive();
                                }
                                catch (SocketException e)
                                {
                                    stateReporter.Report("Socket Error " + e.ErrorCode + ":\n" + e.Message);
                                    break;
                                }

                                if (lastRequestString == null)
                                {
                                    stateReporter.Report("The socket at " + server.RemoteEndPoint + " was shut down.");
                                    break;
                                }
                                else
                                {
                                    stateReporter.Report("Request received from " + server.RemoteEndPoint + ":", lastRequestString, true);
                                }

                                if (AutomaticResponseEnabled)
                                {
                                    RespondAutomatically();
                                }
                            }

                            //if (server.Connected)
                            //{
                            EndPoint remoteEndPoint = server.RemoteEndPoint;
                            server.Disconnect();
                            stateReporter.Report("Disconnected from " + remoteEndPoint + ".");
                            //}
                        }
                    }
                }
                catch (SocketException e)
                {
                    // SocketError.Interrupted is thrown when Dispose() is called
                    // while the TcpIpServer is waiting for a connection using AcceptSocket()
                    // See Stop() below
                    if (e.SocketErrorCode != SocketError.Interrupted)
                    {
                        stateReporter.Report("Socket Error " + e.SocketErrorCode + ":\n" + e.Message);
                    }
                }

                displayedLocalEndPoint = null;
                stateReporter.Report("Server stopped.");
            }));
        }