Home| base |src.lib|tcpip|cnx| ConnexOpen Index

ConnexOpen

Syntax
int ConnexOpen(char *host,int remote_port);
Header
base/connex.h
Library
cnx
Description

The ConnexOpen opens a non-blocking TCP/IP socket stream connection.

The arguments host and remote_port give the hostname and remote port number to connect to.

Returns
Returns the file descriptor of the socket on success. On error, (-1) is returned.
Errors
On error, (-1) is returned.
Example

Source Code: ConnexOpen.c

/* ConnexOpen.c
   ============
   Author: R.J.Barnes
 Copyright (c) 2012 The Johns Hopkins University/Applied Physics Laboratory

This file is part of the Radar Software Toolkit (RST).

RST 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 <https://www.gnu.org/licenses/>.

Modifications:



#include <stdio.h>
#include <stdlib.h>
#include "connex.h"

int main(int argc,char *argv[]) {
  int sock;
  int port=0;
  char *host=NULL;
  int flag,status,size;
  unsigned char *buffer=NULL;
 
  
  if (argc<3) { 
    fprintf(stderr,"host and port must be specified.'n");
    exit(-1);
  }

  host=argv[1];
  port=atoi(argv[2]);
 
  sock=ConnexOpen(host,port); 
  if (sock<0) {
    fprintf(stderr,"Could not connect to host.'n");
    exit(-1);
  }
  do {
   status=ConnexRead(1,&sock,&buffer,&size,&flag,NULL);
   if (status==-1) break;
   if (flag==1) fprintf(stderr,"Message:%s'n",buffer);
     
  } while(1);
  fprintf(stderr,"Connection failed.'n");
  return 0;

}