Top Level Namespace

Defined Under Namespace

Modules: Kernel, N, P, WEBrick Classes: CGI, Class, Logger, Module, NilClass

Constant Summary collapse

EMPTY_STRING =

predefine some comonly used objects

""

Instance Method Summary collapse

Instance Method Details

#connect(srv, port) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/n/sync/clc.rb', line 26

def connect(srv, port)
	begin
		@socket = TCPSocket.new(srv, port)
	rescue
		$log.error "Cannot connect to server, is it online?"
		exit(0)
	end
	$log.info "Connected to #{@socket.addr[3]}:#{@socket.addr[1]}"
end

#promptObject



22
23
24
# File 'lib/n/sync/clc.rb', line 22

def prompt
	printf(Time.now.strftime("%H:%M:%S> "))
end

#readObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/n/sync/clc.rb', line 41

def read()
	begin
		loop do
			timeout(0.7) do
				while @socket.readline("\000")
					$log.info "read: #{$_}"
				end
			end
		end
	rescue TimeoutError
		#drink it
	end
end

#send(str) ⇒ Object



36
37
38
39
# File 'lib/n/sync/clc.rb', line 36

def send(str)
	$log.info "write: #{str}"
	@socket.send("#{str}\000", 0)
end

#write(cmd) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/n/sync/clc.rb', line 55

def write(cmd)
	if cmd = cmd.strip() and not cmd.empty?
		send(cmd)
	 else
		 $log.error "Syntax error"
	 end
end