⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connecttosocket.m

📁 传感器网络中的嵌入式操作系统源代码
💻 M
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -