internal override void InitWork(object stateInfo) { if (!Valid) { return; } if (DccServer != null) { Connection = DccServer.AcceptTcpClient(); RemoteEndPoint = (IPEndPoint)Connection.Client.RemoteEndPoint; DccServer.Stop(); isConnected = true; } else { while (!isConnected) { Thread.Sleep(500); // We wait till Request is Accepted (or jump out when rejected) if (reject) { isValid = false; return; } } } DccChatStartEvent(new DccEventArgs(this)); _sr = new StreamReader(Connection.GetStream(), Irc.Encoding); _sw = new StreamWriter(Connection.GetStream(), Irc.Encoding) { AutoFlush = true }; string line; while (((line = _sr.ReadLine()) != null) && (isConnected)) { DccChatReceiveLineEvent(new DccChatEventArgs(this, line)); Lines++; } isValid = false; isConnected = false; DccChatStopEvent(new DccEventArgs(this)); }
internal override void InitWork(object stateInfo) { if (!Valid) { return; } if (DccServer != null) { Connection = DccServer.AcceptTcpClient(); RemoteEndPoint = (IPEndPoint)Connection.Client.RemoteEndPoint; DccServer.Stop(); isConnected = true; } else { while (!isConnected) { Thread.Sleep(500); // We wait till Request is Accepted (or jump out when rejected) if (reject) { return; } } } DccSendStartEvent(new DccEventArgs(this)); int bytes; if (_DirectionUp) { do { while (Connection.Available > 0) { switch (_Speed) { case DccSpeed.Rfc: Connection.GetStream().Read(_Buffer, 0, _Buffer.Length); // TODO: only send x not ACKed Bytes ahead / (nobody wants this anyway) break; case DccSpeed.RfcSendAhead: Connection.GetStream().Read(_Buffer, 0, _Buffer.Length); break; case DccSpeed.Turbo: // Available > 0 should not happen break; } } bytes = _File.Read(_Buffer, 0, _Buffer.Length); try { Connection.GetStream().Write(_Buffer, 0, bytes); } catch (IOException) { bytes = 0; // Connection Lost } SentBytes += bytes; if (bytes > 0) { DccSendSentBlockEvent(new DccSendEventArgs(this, _Buffer, bytes)); Console.Write("."); } } while (bytes > 0); } else { while ((bytes = Connection.GetStream().Read(_Buffer, 0, _Buffer.Length)) > 0) { _File.Write(_Buffer, 0, bytes); SentBytes += bytes; if (_Speed != DccSpeed.Turbo) { Connection.GetStream().Write(getAck(SentBytes), 0, 4); } DccSendReceiveBlockEvent(new DccSendEventArgs(this, _Buffer, bytes)); } } isValid = false; isConnected = false; Console.WriteLine("--> Filetrangsfer Endet / Bytes sent: " + SentBytes + " of " + _Filesize); DccSendStopEvent(new DccEventArgs(this)); }