示例#1
0
            public HassiumSocket acceptsock(VirtualMachine vm, HassiumObject self, SourceLocation location, params HassiumObject[] args)
            {
                HassiumSocket socket = new HassiumSocket();

                socket.Client = (self as HassiumSocketListener).TcpListener.AcceptTcpClient();

                return(socket);
            }
示例#2
0
            public HassiumObject _new(VirtualMachine vm, HassiumObject self, SourceLocation location, params HassiumObject[] args)
            {
                HassiumSocket socket = new HassiumSocket();
                Stream        stream = null;

                switch (args.Length)
                {
                case 0:
                    socket.Client = new TcpClient();
                    stream        = new MemoryStream();
                    break;

                case 1:
                    if (args[0] is HassiumIPAddr)
                    {
                        var ipAddr = args[0] as HassiumIPAddr;
                        socket.Client = new TcpClient(ipAddr.Address.String, (int)ipAddr.Port.Int);
                        stream        = socket.Client.GetStream();
                    }
                    else
                    {
                        return(_new(vm, self, location, HassiumIPAddr.IPAddrTypeDef._new(vm, null, location, args[0].ToString(vm, args[0], location))));
                    }
                    break;

                case 2:
                    socket.Client = new TcpClient(args[0].ToString(vm, args[0], location).String, (int)args[1].ToInt(vm, args[1], location).Int);
                    stream        = socket.Client.GetStream();
                    break;

                case 3:
                    socket.Client = new TcpClient(args[0].ToString(vm, args[0], location).String, (int)args[1].ToInt(vm, args[1], location).Int);
                    if (args[2].ToBool(vm, args[2], location).Bool)
                    {
                        stream = new SslStream(socket.Client.GetStream(), false, new RemoteCertificateValidationCallback((sender, certificate, chain, sslPolicyErrors) => true), null);
                    }
                    else
                    {
                        stream = socket.Client.GetStream();
                    }
                    break;
                }
                socket.Reader       = new BinaryReader(stream);
                socket.Writer       = new BinaryWriter(stream);
                socket.StreamReader = new StreamReader(stream);
                socket.StreamWriter = new StreamWriter(stream);

                return(socket);
            }