TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Eric Theriault
from: Thomas Seeling
date: 1996-04-23 18:03:16
subject: TCP/IP in OS/2?

Hallo, Eric!

*** Am Montag 22. April 1996 um 02:15 schrieb Eric Theriault an All:

 ET> Does anyone have any information on programming TCP/IP sockets under OS/2
 ET> using EMX?  Thanks.

This is a simple WWW client which does _not_ render output. I use it for
testing my WWW server (Magic TSWWW or homepage at
http://www.uni-giessen.de/~g087/os2dev.html).

Note that a lot of subroutines in IBM's implementation of sockets are not
reentrant, so they may not be used in multithreaded programs without
serialization. This includes nearly all the get* functions.


=== Cut ===
#include 
#include 
#include "www.h"

static int crlf=FALSE;
static int sock=-1;
static int debug=FALSE;

void finish(void) {
  if (sock>=0) {
/*    shutdown(sock,2); */
    close(sock);
  }
  exit(0);
}

void sigpipe(int sig) {
  puts("The server has closed the connection.");
  finish();
}

int rh(int handle, char *buf, int size) {
  return read(handle,buf,size);
}

int wh(int handle, char *buf, int size) {
  char *c;
  int   l=1,save=size;

  c=buf;
  while (l>0 && size--) {
    if (*c=='\n')
      write(handle,"\r",1);
    l=write(handle,c++,1);
  }
  if (l<0)
    return l;
  return save;
}

int transact(int r, int w, char *buf, int s, FILE *ofile) {
  static int doit=FALSE;
  char      *chk;
  int        i;

  do {
    i=rh(r,buf,s);
    if (debug && i>0)
      fprintf(stderr,"Read    % 5d byte from %d\n",i,r);
    if (i>0) {
      if (ofile) {
 if (doit) {
   if (debug)
     fprintf(stderr,"Write   % 5d byte to   output file\n",
      i);
   fwrite(buf,i,1,ofile);
 }
 else {
   chk=buf+3;
   while (chk0 && !ofile)
 fprintf(stderr,"Written % 5d byte to   %d\n",i,w);
    }
    else if (i<0)
      return -1;
  } while (i>0);
  return 0;
}

int main(int argc, char **argv) {
  FILE *out=NULL;
  char  buf[1024];
  char *host="localhost",*ofile=NULL;
  int   i,port=25; /* telnet port */

  while ((i=getopt(argc,argv,"cdo:p:"))!=EOF)
    switch (i) {
    case 'c':
      crlf=TRUE;
      break;
    case 'd':
      debug=TRUE;
      break;
    case 'o':
      ofile=optarg;
      break;
    case 'p':
      port=atoi(optarg);
      break;
    }

  if (optindh_addr,hp->h_length);
    addr.sin_port=htons(port);
  }
  else {
    perror("unknown host");
    return -1;
  }

  if (connect(sock,(struct sockaddr *)&addr,sizeof(addr))<0) {
    perror("connect failed");
    return -1;
  }
  return sock;
}

int waitconnection(struct sockaddr_in *source, int sock) {
  int lg,con_sock;

  lg=sizeof(struct sockaddr_in);
  con_sock=accept(sock, (struct sockaddr *) source, &lg);
  if (con_sock <=0) {
    perror("accept failed");
    exit(1);
  }
  return con_sock;
}
=== Cut ===


Tschau...Thomas

--- E3-32/1.11-32/2.50+
* Origin: Die TeX-Box +49-6034-1455 V.34 -930022 ISDN 24h (2:244/1130.42)
SEEN-BY: 50/99 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1
@PATH: 244/1130 24/999 888 396/1 270/101 712/515 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.