Class: Ji2p::Control::ServerConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/ji2p/control/server.rb

Instance Method Summary collapse

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

#closeObject



15
16
17
# File 'lib/ji2p/control/server.rb', line 15

def close
  @i2pconn.close
end

#getPeerDestinationObject



27
28
29
# File 'lib/ji2p/control/server.rb', line 27

def getPeerDestination
  @i2pconn.getPeerDestination
end

#is_closed?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/ji2p/control/server.rb', line 19

def is_closed?
  @i2pconn.is_closed
end

#rawObject



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

#readlineObject 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

#readybytesObject



51
52
53
# File 'lib/ji2p/control/server.rb', line 51

def readybytes
  @i2pconn.getInputStream.totalReadySize
end

#toStringObject



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