1 /******************************************************************************* 2 3 copyright: Copyright (c) 2006 UWB. All rights reserved 4 5 license: BSD style: $(LICENSE) 6 7 version: Initial release: June 2006 8 Tango Mods by Lester L Martin: August 2008 9 10 author: UWB 11 12 *******************************************************************************/ 13 14 module tango.net.ftp.Telnet; 15 16 private 17 { 18 import tango.core.Exception; 19 import tango.io.stream.Lines; 20 import tango.net.device.Socket; 21 } 22 23 class Telnet 24 { 25 /// The Socket that is used to send commands. 26 Socket socket_; 27 Lines!(char) iterator; 28 29 abstract void exception(string message); 30 31 /// Send a line over the Socket Conduit. 32 /// 33 /// buf = the bytes to send 34 void sendline(const(void)[] buf) 35 { 36 sendData(buf); 37 sendData("\r\n"); 38 } 39 40 /// Send a line over the Socket Conduit. 41 /// 42 /// buf = the bytes to send 43 void sendData(const(void)[] buf) 44 { 45 socket_.write(buf); 46 } 47 48 /// Read a CRLF terminated line from the socket. 49 /// 50 /// Returns: the line read 51 const(char)[] readLine() 52 { 53 const(char)[] to_return; 54 iterator.readln(to_return); 55 return to_return; 56 } 57 58 /************************************************************************ 59 * Find a server which is listening on the specified port. 60 * 61 * Params: 62 * hostname = the hostname to lookup and connect to 63 * port = the port to connect on 64 * Returns: 65 the Socket instance used 66 * Since: 0.99.8 67 */ 68 Socket findAvailableServer(const(char)[] hostname, int port) 69 { 70 socket_ = new Socket; 71 socket_.connect(hostname, port); 72 iterator = new Lines!(char)(socket_); 73 return socket_; 74 } 75 76 }