コード例 #1
0
ファイル: MainForm.cs プロジェクト: souravzzz/subshare
 void init_values()
 {
     groupBox1.Enabled = true;
     groupBox2.Enabled = false;
     m_remember_b = false;
     m_my_ip = get_my_ip();	//hopefully i will get my desired one!
     m_my_port = (new Random()).Next(1025,65535);	//choose a random port, what if it is not free?
     m_my_addr = new IPEndPoint(m_my_ip,m_my_port);
     ssock = csock = dlsock =null;
     m_SSRO = null;
     m_continue_listening = false;
     m_continue_downloading = false;
     m_chunk_size = 1024*60; //60KB
 }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: souravzzz/subshare
        bool connect_to_server()
        {
            //true on success, false on failure
            string url = @"tcp://"+m_server_addr+@"/SUBSERVER";

            TcpChannel chan=null;
            try {
                BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
                IDictionary props = new Hashtable();
                props["port"] = 0;
                //all this shit just to prevent a stupid error!
                //i am passing custom objects through this channel and .NET 1.1 does not like it
                //so i have to set TypeFilterLevel=FULL and they dont have any stupid property or constructor for that

                chan = new TcpChannel(props, clientProv, serverProv);
                ChannelServices.RegisterChannel(chan,false);
                m_SSRO = (subshareRemoteObject)Activator.GetObject(typeof(subshareRemoteObject),url);	//get reference to the remote object
                if(m_SSRO==null)	//bad luck, try again!
                    return false;
                populate_filedata();
            } catch(Exception ex) {
                if(chan!=null)
                    ChannelServices.UnregisterChannel(chan);	//unregister so that you can try again
                chan = null;
                LOGFILE.WriteLine("CAN NOT CONNECT TO SERVER "+ex);
                return false;
            }
            return true;
        }