No BSD License
-
tcp_close(tcp_client_h)
% TCP_CLOSE closes the open socket, which the supplied handle
-
tcp_connect(ip_address, port_...
% TCP_CONNECT instances an ActiveX object from atlSocket DLL,
-
tcp_geterror(tcp_client_h)
% TCP_GETERROR returns a string, containg the last error
-
tcp_getserveripaddress(tcp_cl...
% TCP_GETSERVERIPADDRESS returns a string containing the server's
-
tcp_getserverportnum(tcp_clie...
% TCP_GETSERVERIPADDRESS returns the TCP port number, on the server,
-
tcp_getsocketerrorcode(tcp_cl...
% TCP_GETSOCKETERRORCODE returns the last error code, that the underlying
-
tcp_recv(tcp_client_h, vec_le...
% TCP_RECV reads a vector from an open socket.
-
tcp_send(tcp_client_h, buff, ...
% TCP_SEND sends a vector to the server, through an open socket.
-
View all files
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