Module: Network

Included in:
MCBasePatternHelper
Defined in:
lib/common/socket/network.rb

Overview

网络交互服务顶层接口e.g. nshead_send, shead_send

Author

chenjie

Data

2009-4-30

Instance Method Summary collapse

Instance Method Details

#g_send(host, querykey, driver, headtype, datapath, datafile, resultpath, resultfile) ⇒ Object

功能

使用my_clinet发送数据

example

g_send host, “spanti”, “spanti_driver.so”, “nshead”, path1, file1, path2, file2



69
70
71
72
73
74
# File 'lib/common/socket/network.rb', line 69

def g_send(host, querykey, driver, headtype, datapath, datafile, resultpath, resultfile)
	my_client_path=TOOL_ROOT+"net/my_client/"
	send_cmd="cd #{my_client_path} && ./my_client -q #{querykey} -d #{driver} -t #{headtype} -a #{host} -p #{datapath} -c #{datafile} -r #{resultpath} -f #{resultfile}"
	
	system "#{send_cmd}"
end

#nshead_send(ip, port, nshead_hash, send_data, recv_data, interval = 0) ⇒ Object

功能

向指定目标发送指定内容的mcpack包(mcsend)

参数

params: ip: 目标机器ip port: 目标机器端口nshead hash: 定制的nshead文件路径(需要指定nshead头参数时使用,NULL表示使用默认值) send_data: 待发送mcpack文本路径recv_data: 待接收另存的mcpack文本路径interval: 两次发送之间的时间间隔,单位为秒

example

nshead_send “127.0.0.1”, 3390, nsheadhash, sendfile, recvfile



26
27
28
29
30
31
32
33
34
35
# File 'lib/common/socket/network.rb', line 26

def nshead_send ip, port, nshead_hash, send_data, recv_data, interval=0
	ms_path=TOOL_ROOT+"net/mcsend/"
	nshead_file = "nshead.data"
	if nil != :nshead_hash then
		Env.modify_conf('127.0.0.1', USERNAME, PASSWORD, ms_path + nshead_file, nshead_hash)
	end
	send_cmd = "cd #{ms_path} && ./mcsend -s -i #{ip} -p #{port} -n #{nshead_file} -b #{send_data} -o #{recv_data} -t #{interval}"
	$log.debug send_cmd
	system "#{send_cmd}"
end

#nshead_trans_send(ip, port, nshead_hash, send_data, recv_data, interval = 0) ⇒ Object

功能

向指定目标发送指定内容的mcpack包(mcsend_trans)

参数

params: ip: 目标机器ip port: 目标机器端口nshead hash: 定制的nshead文件路径(需要指定nshead头参数时使用,NULL表示使用默认值) send_data: 待发送mcpack文本路径recv_data: 待接收另存的mcpack文本路径interval: 两次发送之间的时间间隔,单位为秒

example

nshead_trans_send “127.0.0.1”, 3390, nsheadhash, sendfile, recvfile



50
51
52
53
54
55
56
57
58
59
# File 'lib/common/socket/network.rb', line 50

def nshead_trans_send ip, port, nshead_hash, send_data, recv_data, interval=0
	ms_path=TOOL_ROOT+"net/mcsend/"
	nshead_file = "nshead.data"
	if nil != :nshead_hash then
		Env.modify_conf('127.0.0.1', USERNAME, PASSWORD, ms_path + nshead_file, nshead_hash)
	end
	send_cmd = "cd #{ms_path} && ./mcsend_trans -s -i #{ip} -p #{port} -n #{nshead_file} -b #{send_data} -o #{recv_data} -t #{interval}"
	$log.debug send_cmd
	system "#{send_cmd}"
end

#send_mcpack(host, headtype, datapath, datafile, resultpath, resultfile) ⇒ Object

功能

使用my_client发送数据

example

send_mcpack host, “nshead”, path, file, rpath, rfile



80
81
82
83
84
85
# File 'lib/common/socket/network.rb', line 80

def send_mcpack(host, headtype, datapath, datafile, resultpath, resultfile)
	my_client_path=TOOL_ROOT+"net/my_client/"
	send_cmd="cd #{my_client_path} && ./my_client -t #{headtype} -a #{host} -p #{datapath}  -c #{datafile} -r #{resultpath} -f #{resultfile}"
	
	system "#{send_cmd}"
end

#shead_send(ip, port, send_data_file, recv_data_file, diver = nil) ⇒ Object



62
63
# File 'lib/common/socket/network.rb', line 62

def shead_send(ip, port, send_data_file, recv_data_file, diver=nil)
end