Socket Verbindung AV-Reciver

M

martin2day

Mitglied
Thread Starter
Dabei seit
24.08.2004
Beiträge
79
Reaktionspunkte
0
Hallöchen,

ich habe mir einen neuen AV-Tuner von Pioneer gekauft. Für diesen gibt es bereits Apps für iPhone und iPad zum fern bedienen.

Allerdings möchte ich dies gern von meinem MacBook Pro aus machen können. Später soll das ganze auch von einer Steuerung im Haus möglich sein.

Ich habe schon herausgefunden das ich eine Socketverbindung mit dem Port 8102 des Tuners aufbauen muss. Auch habe ich von Pioneer eine Liste mit Befehlen dich ich zum erhalten bzw. verändern von Daten an den Tuner schicken muss.

Allerdings fehlt mir ein wenig das Hintergrundwissen wie ich das m besten in OSX umsetzen kann. Kleine Script habe ich schon erstellt.

Wer kann mir einen Tipp geben wie ich das umsetzen kann?

Danke schon mal
Gruß Martin
 
Kannst Du uns die Dokumentation zur Verfügung stellen?

Was für Scripte hast Du geschrieben?

Alex
 
Danke. Und welches Vorwissen hast Du?

Alex
 
Hey Alex,

ich habe schon etliche Sache in Assembler und C geschrieben. Auch einige Systemscripte sowohl auf Windows wie auch auf meinem MAC.
Über Socket Verbindungen habe ich kein Wissen.

Martin
 
C hört sich doch gar nicht schlecht an

Hier mal ein Beispiel, wie sockets auf dem Mac funktionieren:

Code:
/*
 * All this is from:
 *
 * http://world.std.com/~jimf/papers/sockets/sockets.html
 *
 */

#include <errno.h>       /* obligatory includes */
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <netdb.h>

#define PORTNUM 50000 /* random port number, we need something */

void fireman(void);
void do_something(int);

/* code to establish a socket; originally from bzs@bu-cs.bu.edu
 */

#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 255
#endif

int establish(unsigned short portnum)
{ char   myname[MAXHOSTNAMELEN];
  int    s;
  struct sockaddr_in sa;
  struct hostent *hp;

  memset(&sa, 0, sizeof(struct sockaddr_in)); /* clear our address */
  gethostname(myname, MAXHOSTNAMELEN);           /* who are we? */
  hp= gethostbyname(myname);                  /* get our address info */
  if (hp == NULL)                             /* we don't exist !? */
    return(-1);
  sa.sin_family= hp->h_addrtype;              /* this is our host address */
  sa.sin_port= htons(portnum);                /* this is our port number */
  if ((s= socket(AF_INET, SOCK_STREAM, 0)) < 0) /* create socket */
    return(-1);
  if (bind(s,(struct sockaddr *)&sa,sizeof(struct sockaddr_in)) < 0) {
    close(s);
    return(-1);                               /* bind address to socket */
  }
  listen(s, 3);                               /* max # of queued connects */
  return(s);
}

/* wait for a connection to occur on a socket created with establish()
 */
int get_connection(int s)
{ int t;                  /* socket of connection */

  if ((t = accept(s,NULL,NULL)) < 0)   /* accept connection if there is one */
    return(-1);
  return(t);
}

main()
{ int s, t;

  if ((s= establish(PORTNUM)) < 0) {  /* plug in the phone */
    perror("establish");
    exit(1);
  }

  signal(SIGCHLD, fireman);           /* this eliminates zombies */

  for (;;) {                          /* loop for phone calls */
    if ((t= get_connection(s)) < 0) { /* get a connection */
      if (errno == EINTR)             /* EINTR might happen on accept(), */
        continue;                     /* try again */
      perror("accept");               /* bad */
      exit(1);
    }
    switch(fork()) {                  /* try to handle connection */
    case -1 :                         /* bad news.  scream and die */
      perror("fork");
      close(s);
      close(t);
      exit(1);
    case 0 :                          /* we're the child, do something */
      close(s);
      do_something(t);
      exit(0);
    default :                         /* we're the parent so look for */
      close(t);                       /* another connection */
      continue;
    }
  }
}

/* as children die we should get catch their returns or else we get
 * zombies, A Bad Thing.  fireman() catches falling children.
 */
void fireman(void)
{
  while (waitpid(-1, NULL, WNOHANG) > 0)
    ;
}

int read_data(int s,     /* connected socket */
              char *buf, /* pointer to the buffer */
              int n      /* number of characters (bytes) we want */
             )
{ int bcount; /* counts bytes read */
  int br;     /* bytes read this pass */

  bcount= 0;
  br= 0;
  while (bcount < n) {             /* loop until full buffer */
    if ((br= read(s,buf,n-bcount)) > 0) {
      bcount += br;                /* increment byte counter */
      buf += br;                   /* move buffer ptr for next read */
    }
    else if (br < 0)               /* signal an error to the caller */
      return(-1);
  }
  return(bcount);
}

/* this is the function that plays with the socket.  it will be called
 * after getting a connection.
 */
void do_something(int s)
{
	char c;
	int err;
  /* do your thing with the socket here
      :
      :
   */
	printf ("The connection is made: ");
	err = read_data (s, &c, 1);
	printf ("%c");
}

Fragen?

Alex
 
Zurück
Oben Unten