Class: Ji2p::Control::ServerConnection
- Defined in:
- lib/ji2p/control/server.rb
Instance Method Summary collapse
- #close ⇒ Object
- #getPeerDestination ⇒ Object
-
#initialize(i2pconn) ⇒ ServerConnection
constructor
A new instance of ServerConnection.
- #is_closed? ⇒ Boolean
- #raw ⇒ Object
- #readbytes(n = nil) ⇒ Object
- #readline ⇒ Object (also: #gets)
- #readstring(n = nil) ⇒ Object (also: #read)
- #readybytes ⇒ Object
- #toString ⇒ Object
- #write(data) ⇒ Object (also: #puts)
Constructor Details
#initialize(i2pconn) ⇒ ServerConnection
Returns a new instance of ServerConnection.
7 8 9 |
# File 'lib/ji2p/control/server.rb', line 7 def initialize i2pconn @i2pconn = i2pconn end |
Instance Method Details
#close ⇒ Object
15 16 17 |
# File 'lib/ji2p/control/server.rb', line 15 def close @i2pconn.close end |
#getPeerDestination ⇒ Object
27 28 29 |
# File 'lib/ji2p/control/server.rb', line 27 def getPeerDestination @i2pconn.getPeerDestination end |
#is_closed? ⇒ Boolean
19 20 21 |
# File 'lib/ji2p/control/server.rb', line 19 def is_closed? @i2pconn.is_closed end |
#raw ⇒ Object
11 12 13 |
# File 'lib/ji2p/control/server.rb', line 11 def raw @i2pconn end |
#readbytes(n = nil) ⇒ Object
45 46 47 48 49 |
# File 'lib/ji2p/control/server.rb', line 45 def readbytes n=nil return nil if is_closed? num = n || readybytes @i2pconn.getInputStream.readNBytes num end |
#readline ⇒ Object Also known as: gets
35 36 37 38 39 40 41 42 43 |
# File 'lib/ji2p/control/server.rb', line 35 def readline line = "" loop { c = String.from_java_bytes(readbytes(1)) break if c=="\n" line += c } line + "\n" end |
#readstring(n = nil) ⇒ Object Also known as: read
31 32 33 |
# File 'lib/ji2p/control/server.rb', line 31 def readstring n=nil String.from_java_bytes readbytes(n || readybytes) end |
#readybytes ⇒ Object
51 52 53 |
# File 'lib/ji2p/control/server.rb', line 51 def readybytes @i2pconn.getInputStream.totalReadySize end |
#toString ⇒ Object
59 60 61 62 |
# File 'lib/ji2p/control/server.rb', line 59 def toString b32 = @i2pconn.getPeerDestination.toBase32 "<ServerConnection client=#{b32} is_closed=#{@i2pconn.is_closed}>" end |
#write(data) ⇒ Object Also known as: puts
23 24 25 |
# File 'lib/ji2p/control/server.rb', line 23 def write data @i2pconn.getOutputStream.write data.to_java_bytes end |