No BSD License  

Highlights from
atlSocket

from atlSocket by David Ganor
A TCP/IP client-side socket entity implemented as an ActiveX DLL.

tcp_connect(ip_address, port_num)
function tcp_client_h = tcp_connect(ip_address, port_num)
%
% TCP_CONNECT instances an ActiveX object from atlSocket DLL,
% creates a TCP client-side socket entity and opens a socket
% to a server with designated IP address and port number.
% The function returns the handle to the object or an empty
% result with an error.
%
% IMPORTANT: IT IS ASSUMED THAT THE SERVER IS A BIG-ENDIAN MACHINE,
% HENCE, EACH ELEMENT'S HEXADECIMAL BYTE-REPRESENTATION IS SWAPPED.
%
%   tcp_client_h = tcp_connect(ip_address, port_num)
%

% Author:       David Ganor, WAVION Ltd.
% Last Update:  09/2003
% Revisions:
%   1. Created.

%% Checking input arguments
if (nargin ~= 2)
    error('Wrong number of input arguments');
end
if ~ischar(ip_address)
    error('1st input argument must be a string holding an IP address');
end
if ~isreal(port_num)
    error('2nd input argument must be a real number');
end

%% Creating ActiveX object
tcp_client_h = actxserver('AtlSocket.TCP_CLIENT');
if ~isobject(tcp_client_h) | isempty(tcp_client_h)
    error('Creating TCP_CLIENT ActiveX object failed');
end

%% Connecting to server
result = invoke(tcp_client_h, 'tcp_connect', ip_address, port_num);
if (result ~= -1)
    error_str = tcp_geterror(tcp_client_h);
    release(tcp_client_h);
    tcp_client_h = [];
    if ~isempty(error_str)
        error(['ActiveX object: ' error_str]);
    else
        error(['TCP connect to ' ip_address ':' num2str(port_num) ' failed without any error reported inside ActiveX object']);
    end
end

Contact us at files@mathworks.com