public StrongConnect(string host, int port, string fn)
        {
            Socket?socket = null;

            try
            {
                IPEndPoint ep;
                socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                if (char.IsDigit(host[0]))
                {
                    IPAddress ip = IPAddress.Parse(host);
                    ep = new IPEndPoint(ip, port);
                    socket.Connect(ep);
                }
                else
                {
#if MONO1
                    var he = Dns.GetHostByName(hostName);
#else
                    IPHostEntry he = Dns.GetHostEntry(host);
#endif
                    for (int j = 0; j < he.AddressList.Length; j++)
                    {
                        try
                        {
                            IPAddress ip = he.AddressList[j];
                            ep = new IPEndPoint(ip, port);
                            socket.Connect(ep);
                            if (socket.Connected)
                            {
                                break;
                            }
                        }
                        catch (Exception) { }
                    }
                }
            }
            catch (Exception)
            {
            }
            if (socket == null || !socket.Connected)
            {
                throw new Exception("No connection to " + host + ":" + port);
            }
            asy = new ClientStream(this, socket);
            var wtr = asy.wtr;
            wtr.PutString(fn);
            asy.Flush();
            asy.Receive();
            preps = SDict <long, string> .Empty;
        }
Ejemplo n.º 2
0
        public DocArray Get(Serialisable tn)
        {
            asy.Write(Types.DescribedGet);
            tn.Put(asy);
            asy.Flush();
            var b = asy.ReadByte();

            if (b == (byte)Types.Exception)
            {
                inTransaction = false;
                asy.GetException();
            }
            if (b == (byte)Types.Done)
            {
                description = SDict <int, string> .Empty;
                var n = asy.rbuf.GetInt();
                for (var i = 0; i < n; i++)
                {
                    description += (i, asy.rbuf.GetString());
                }
                return(new DocArray(asy.rbuf.GetString()));
            }
            throw new Exception("??");
        }