Class: DCCClient
Instance Method Summary
collapse
-
#client_recv(&action) ⇒ Object
-
#client_recv7(filename, filesize, offset, &callback) ⇒ Object
-
#client_send(filename, &callback) ⇒ Object
-
#client_send7(filename, filesize, offset, &callback) ⇒ Object
-
#initialize(host, port, client_uin, server_uin, code = nil) ⇒ DCCClient
constructor
A new instance of DCCClient.
Methods inherited from DCCServer
#add_recv_code, #add_send, #add_send_code, #close, #init_recv, #init_send, #on_recv, #progress, #recv, #recv7, #send, #send7, #server, #wait
Constructor Details
#initialize(host, port, client_uin, server_uin, code = nil) ⇒ DCCClient
Returns a new instance of DCCClient.
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/gg/dccclient.rb', line 6
def initialize(host, port, client_uin, server_uin, code=nil)
@client_uin, @server_uin, @code = client_uin, server_uin, code
@progress, @callback = {}, {}
@socket = TCPSocket.new(host, port)
if code
@socket.write(code)
@socket.read(8)
else
@socket.write([client_uin, server_uin].pack('LL'))
@socket.read(4)
end
end
|
Instance Method Details
#client_recv(&action) ⇒ Object
25
26
27
28
29
|
# File 'lib/gg/dccclient.rb', line 25
def client_recv(&action)
@prepare_recv = action
@socket.write([0x03].pack('L'))
init_recv(@socket, @server_uin)
end
|
#client_recv7(filename, filesize, offset, &callback) ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/gg/dccclient.rb', line 42
def client_recv7(filename, filesize, offset, &callback)
@callback[@code] = callback if callback
begin
recv7(@code, @socket, filename, filesize, offset)
rescue SystemCallError, RuntimeError
callback.call(:aborted) if callback
ensure
@progress.delete(@server_uin)
end
end
|
#client_send(filename, &callback) ⇒ Object
19
20
21
22
23
|
# File 'lib/gg/dccclient.rb', line 19
def client_send(filename, &callback)
@callback[@server_uin] = callback if callback
@socket.write([0x02].pack('L'))
init_send(@server_uin, @socket, filename)
end
|
#client_send7(filename, filesize, offset, &callback) ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/gg/dccclient.rb', line 31
def client_send7(filename, filesize, offset, &callback)
@callback[@code] = callback if callback
begin
send7(@code, @socket, filename, filesize, offset)
rescue SystemCallError
callback.call(:aborted)
ensure
@progress.delete(@server_uin)
end
end
|