Exemple #1
0
        private bool TestClient(string content, string ipEndPointAddress, out Socket s)
        {
            s = null;
            if (!IPEndPointHelper.TryParseEndPoint(ipEndPointAddress, out var ep, out var msg))
            {
                output.WriteLine(msg);
                return(false);
            }
            var result = false;

            s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            s.Connect(ep);
            byte[] buffer = new byte[4096];
            var    length = s.Receive(buffer);

            if (length == 0)
            {
                output.WriteLine("remote closed unexcepted");
                return(false);
            }
            if (Encoding.UTF8.GetString(buffer.Take(length).ToArray()) == content)
            {
                result = true;
            }
            else
            {
                output.WriteLine("received result not same");
            }
            return(result);
        }
Exemple #2
0
        private bool TestTCPServer(string testContent, string ipendpointandport, out Socket s)
        {
            s = null;
            if (!IPEndPointHelper.TryParseEndPoint(ipendpointandport, out var ep, out var msg))
            {
                output.WriteLine(msg);
                return(false);
            }

            IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();

            if (properties.GetActiveTcpListeners().Any(x => x.Address.Equals(ep.Address) && x.Port == ep.Port))
            {
                output.WriteLine("port has been used " + ep.Port);
                return(false);
            }


            s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            s.Bind(ep);
            s.Listen(10);
            s.AcceptAsync().ContinueWith(x =>
            {
                if (x.Exception == null)
                {
                    var ns = x.Result;
                    ns.Send(Encoding.UTF8.GetBytes(testContent));

                    //					ns.Shutdown(SocketShutdown.Send);
                    //					ns.Close();
                }
            });

            return(true);
        }
Exemple #3
0
        private bool TestTTTService(string ip, int listenPortForService, string serviceListeningip, string testServerEPAddress, out TransferServer ts)
        {
            ts = null;
            var result = false;

            if (!IPEndPointHelper.TryParseEndPoint(ip + ":" + listenPortForService, out var ep, out var msg))
            {
                output.WriteLine(msg);
                return(result);
            }
            if (!IPEndPointHelper.TryParseEndPoint(serviceListeningip, out var listenEp, out var msg2))
            {
                output.WriteLine(msg2);
                return(result);
            }
            if (!IPEndPointHelper.TryParseEndPoint(testServerEPAddress, out var testServerEP, out var msg3))
            {
                output.WriteLine(msg3);
                return(result);
            }

            ts     = new TransferServer(listenEp, ep, testServerEP, new BaseLogger(new TestLogger(output)));
            result = true;
            return(result);
        }