StartAsyncReceive() публичный Метод

public StartAsyncReceive ( ) : void
Результат void
Пример #1
0
 private void OnRequested(IAsyncResult r)
 {
     try {
         if (_closed)
         {
             return; //SSH切断があったときは非同期受信から戻ってくるが、EndAcceptを呼んでもObjectDisposedExceptionになるだけ
         }
         Socket local = _bindedLocalSocket.EndAccept(r);
         //Port Forwarding
         Channel newchannel = new Channel(_profile.SSHHost, local.RemoteEndPoint.ToString(), _id, null, local);
         lock (_connection) {
             SSHChannel remote = _connection.ForwardPort(newchannel, _profile.DestinationHost, _profile.DestinationPort, "localhost", 0); //!!最後の2つの引数未完
             Debug.WriteLine("OnRequested ch=" + remote.LocalChannelID);
             newchannel.FixChannel(remote);
             newchannel.StartAsyncReceive();
         }
     }
     catch (Exception ex) {
         if (!_closed)
         {
             Debug.WriteLine(ex.Message);
             Debug.WriteLine(ex.StackTrace);
             Util.InterThreadWarning(ex.Message);
         }
     }
     finally {
         if (!_closed)
         {
             _bindedLocalSocket.BeginAccept(new AsyncCallback(OnRequested), null);
             Debug.WriteLine("BeginAccept again");
         }
     }
 }
Пример #2
0
        public RemotePortForwardingReply OnRemotePortForwardingRequest(RemotePortForwardingRequest request, ISSHChannel channel)
        {
            try {
                if (!_profile.AllowsForeignConnection && !IsLoopbackAddress(request.OriginatorIp))
                {
                    return(RemotePortForwardingReply.Reject(
                               RemotePortForwardingReply.Reason.AdministrativelyProhibited, "rejected"));
                }

                Socket local = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                local.Connect(new IPEndPoint(Util.ResolveHost(_profile.DestinationHost), _profile.DestinationPort));

                var newChannel =
                    new Channel(
                        _profile.SSHHost, _profile.DestinationHost, (int)channel.LocalChannel, channel, local);

                newChannel.StartAsyncReceive();

                return(RemotePortForwardingReply.Accept(newChannel));
            }
            catch (Exception ex) {
                Debug.WriteLine(ex.StackTrace);
                Util.InterThreadWarning(ex.Message);
                return(RemotePortForwardingReply.Reject(
                           RemotePortForwardingReply.Reason.AdministrativelyProhibited, "rejected"));
            }
        }
Пример #3
0
 public override void EstablishPortforwarding(ISSHChannelEventReceiver receiver, SSHChannel channel)
 {
     try {
         Channel ch = (Channel)receiver;
         ch.FixChannel(channel);
         ch.OnChannelReady();
         ch.StartAsyncReceive();
     }
     catch (Exception ex) {
         Debug.WriteLine(ex.StackTrace);
         Util.InterThreadWarning(ex.Message);
     }
 }
Пример #4
0
 private void OnRequested(IAsyncResult r)
 {
     try {
         Socket local = _bindedLocalSocket.EndAccept(r);
         //Port Forwarding
         Channel newchannel = new Channel(_profile.SSHHost, local.RemoteEndPoint.ToString(), _id, null, local);
         lock(_connection) {
             SSHChannel remote = _connection.ForwardPort(newchannel, _profile.DestinationHost, _profile.DestinationPort, "localhost", 0); //!!�Ō�̂Q�‚̈�������
             Debug.WriteLine("OnRequested ch="+remote.LocalChannelID);
             newchannel.FixChannel(remote);
             newchannel.StartAsyncReceive();
         }
     }
     catch(Exception ex) {
         if(!_closed) {
             Debug.WriteLine(ex.Message);
             Debug.WriteLine(ex.StackTrace);
             Util.InterThreadWarning(ex.Message);
         }
     }
     finally {
         if(!_closed)
             _bindedLocalSocket.BeginAccept(new AsyncCallback(OnRequested), null);
     }
 }
Пример #5
0
 private void OnRequested(IAsyncResult r) {
     try {
         if (_closed)
             return; //SSH切断があったときは非同期受信から戻ってくるが、EndAcceptを呼んでもObjectDisposedExceptionになるだけ
         Socket local = _bindedLocalSocket.EndAccept(r);
         //Port Forwarding
         Channel newchannel = new Channel(_profile.SSHHost, local.RemoteEndPoint.ToString(), _id, null, local);
         lock (_connection) {
             SSHChannel remote = _connection.ForwardPort(newchannel, _profile.DestinationHost, _profile.DestinationPort, "localhost", 0); //!!最後の2つの引数未完
             Debug.WriteLine("OnRequested ch=" + remote.LocalChannelID);
             newchannel.FixChannel(remote);
             newchannel.StartAsyncReceive();
         }
     }
     catch (Exception ex) {
         if (!_closed) {
             Debug.WriteLine(ex.Message);
             Debug.WriteLine(ex.StackTrace);
             Util.InterThreadWarning(ex.Message);
         }
     }
     finally {
         if (!_closed) {
             _bindedLocalSocket.BeginAccept(new AsyncCallback(OnRequested), null);
             Debug.WriteLine("BeginAccept again");
         }
     }
 }
Пример #6
0
        public RemotePortForwardingReply OnRemotePortForwardingRequest(RemotePortForwardingRequest request, ISSHChannel channel)
        {
            try {
                if (!_profile.AllowsForeignConnection && !IsLoopbackAddress(request.OriginatorIp)) {
                    return RemotePortForwardingReply.Reject(
                            RemotePortForwardingReply.Reason.AdministrativelyProhibited, "rejected");
                }

                Socket local = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                local.Connect(new IPEndPoint(Util.ResolveHost(_profile.DestinationHost), _profile.DestinationPort));

                var newChannel =
                    new Channel(
                        _profile.SSHHost, _profile.DestinationHost, (int)channel.LocalChannel, channel, local);

                newChannel.StartAsyncReceive();

                return RemotePortForwardingReply.Accept(newChannel);
            }
            catch (Exception ex) {
                Debug.WriteLine(ex.StackTrace);
                Util.InterThreadWarning(ex.Message);
                return RemotePortForwardingReply.Reject(
                        RemotePortForwardingReply.Reason.AdministrativelyProhibited, "rejected");
            }
        }