connecttosocket.m

来自「这是无线传感器网络用的操作系统tinyos-1.1.0,未来的世界将是它呵」· M 代码 · 共 41 行

M
41
字号
function moteIF = connectToSocket(socket)
%CONNECTTOSOCKET
%
% usage: moteIF = connectToSocket('localhost:9000')
%
%This function takes a string and connects to that socket.
%
%If the connection already exists, it returns the moteIF object that did
%it.
%
%IF the connection cannot be made, an error is given.

global COMM

c=find(socket==':');
if ~ischar(socket) | isempty(c) | c==1 | c==length(socket)
    warning(' usage: connectToSocket(''localhost:9000'')');
end

TF=strcmp(COMM.sockets, socket);
if any(TF)
    moteIF=COMM.moteIF{TF};
    return
end

try
    host=socket(1:c-1);
    port=str2num(socket(c+1:end));
    moteIF = net.tinyos.message.MoteIF(host, port, COMM.groupID, COMM.packetLength, 0);
    moteIF.start;
    COMM.sockets{end+1}=socket;
    COMM.moteIF{end+1}=moteIF;
catch
    moteIF=[];
    warning(['Could not connect: ' socket])
end

    
    
    
    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?