summaryrefslogtreecommitdiff
path: root/inst/tcpip.m
blob: eec4277a0dccb38e9c13942c20f1c79a44a8b5bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
## Copyright (C) 2018-2019 John Donoghue <john.donoghue@ieee.org>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {@var{tcp} = } tcpip (@var{host}, [@var{port}], [@var{PropertyName}, @var{PropertyValue}...])
## Matlab compatible wrapper to the tcp interface.
##
## NOTE: tcpip has been deprecated. Use tcpclient instead
##
## @subsubheading Inputs
## @var{host} - the host name or ip.@*
## @var{port} - the port number to connect. If omitted defaults to 80.@*
## @var{PropertyName}, @var{PropertyValue} - Optional property name, value pairs to set on the tcp object.@*
##
## @subsubheading Properties
## Currently the only known properties are "timeout" and "name".
##
## @subsubheading Outputs
## tcpip will return an instance of @var{octave_tcp} class as the result.
## @end deftypefn

function out = tcpip (varargin)

  persistent warned = false;
  if (! warned)
    warned = true;
    warning ("Octave:deprecated-function",
             "tcpip is obsolete and will be removed from a future version of instrument-control, please use 'tcpclient' instead");
  endif

  if nargin == 0 || (nargin > 1 && !isnumeric(varargin{2}))
    print_usage ();
  endif

  host = varargin{1};

  if nargin > 1
    port = varargin{2};
  else
    port = 80;
  endif

  if nargin > 2
    if mod(nargin, 2) != 0
      error ("tcpip: expected property name, value pairs");
    endif
    if !iscellstr (varargin(3:2:nargin))
      error ("tcpip: expected property names to be strings");
    endif
  endif

  out = tcp (resolvehost(host, "address"), port);

  for i = 3:2:nargin
    propname = tolower(varargin{i});
    propvalue = varargin{i+1};

    __tcp_properties__ (out, propname, propvalue);
  endfor

endfunction

%!test
%! a = tcpip ("octave.org", 80);
%! assert(isa(a, "octave_tcp"));
%! fclose(a);