Transport mechanisms

Connecting devices



Wired characteristics

Wireless characteristics


Ethernet


Serial/parallel cable


USB


Firewire


1-wire


Power cables - X10


X10 modules


WiFi


Bluetooth


Infrared


Consumer infrared


iRda


RFID tags


Typical system



Data rates

1000x800 256 RGB @ 30 fps 7.2 Mbps
MPEG-1 encoding 325x140 @ 30fps 1.5 Mbps
HDTV 1920x1080 @ 30fps 80 Mbps
Audio CD 16 bit 44.1k samples per second 1.35 Mbps
MP3 (typical quality) 0.13 Mbps

Making audio available on the internet


Internet loudspeaker


Speaker server code


#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

#define SIZE 1024
char buf[SIZE];

#define SPEAKER_PORT 2013

void copy_to_speaker(int speaker_in) {
    int pfd[2];
    int pid;
    int nread;

    if (pipe(pfd) == -1) {
	perror("pipe failed");
	exit(1);
    }
    if ((pid = fork()) < 0) {
	perror("fork failed");
	exit(2);
    }
    if (pid == 0) {
	close(pfd[1]);
	dup2(pfd[0], 0);
	close(pfd[0]);
	execlp("sox", "sox",
	       "-t", "au", "-",
	       "-t", "ossdsp",
	       "/dev/dsp",
	       NULL);
	perror("play failed");
	exit(3);
    } else {
	close(pfd[0]);

	while ((nread = read(speaker_in, buf, SIZE)) > 0) {
	    write(pfd[1], buf, nread);
	}
	close(pfd[1]);
    }
}

int main(int argc, 
         char *argv[]) {
    int sockfd, client_sockfd;
    int nread, len;
    struct sockaddr_in serv_addr,
	client_addr;
    
    /* create endpoint */
    if ((sockfd =
	 socket(AF_INET,
		SOCK_STREAM, 0))
	< 0) {
	perror(NULL);
	exit(2);
    }
    
    /* bind address */
    serv_addr.sin_family =
	AF_INET;
    serv_addr.sin_addr.s_addr =
	htonl(INADDR_ANY);
    serv_addr.sin_port =
	htons(SPEAKER_PORT);
    
    if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
	perror(NULL);
	exit(3);
    }
    
    /* specify queue */
    listen(sockfd, 5);
    for (;;) {
	len = sizeof(client_addr);
	client_sockfd =
	    accept(sockfd,
		   (struct sockaddr *) &client_addr,
		   &len);
	if (client_sockfd == -1) {
	    perror(NULL);
	    continue;
	}
	
	/* transfer data */
	copy_to_speaker(client_sockfd);
	close(client_sockfd);
    }
}

Sound source code


#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/stat.h>
#include <fcntl.h>


#define SIZE 1024
char buf[SIZE];

#define SPEAKER_PORT 2013

void send_to_speaker(int speaker_port) {
    int pfd[2];
    int pid;
    int nread;

    if (pipe(pfd) == -1) {
	perror("pipe failed");
	exit(1);
    }
    if ((pid = fork()) < 0) {
	perror("fork failed");
	exit(2);
    }
    if (pid == 0) {
	close(pfd[0]);
	dup2(pfd[1], 1);
	close(pfd[1]);
	execlp("rec", "rec",
	       "-s", "w",
	       "-c", "2",
	       "-r", "44100",
	       "-t", "wav", "-",
	       NULL);
	perror("play failed");
	exit(3);
    } else {
	close(pfd[1]);

	while ((nread = read(pfd[0], buf, SIZE)) > 0) {
	    write(speaker_port, buf, nread);
	}
	close(pfd[0]);
    }
}

int main(int argc, 
         char *argv[]) {
    int sockfd;
    int audio_file;
    int nread;
    struct sockaddr_in serv_addr;
    
    if (argc != 2) {
	fprintf(stderr,
		"usage: %s IPaddr\n",
		argv[0]);
	exit(1);
    }
    
    /* create endpoint */
    if ((sockfd =
	 socket(AF_INET,
		SOCK_STREAM, 0))
	< 0) {
	perror(NULL);
	exit(2);
    }
    
    /* connect to server */
    serv_addr.sin_family =
	AF_INET;
    serv_addr.sin_addr.s_addr =
	inet_addr(argv[1]);
    serv_addr.sin_port =
	htons(SPEAKER_PORT);
    if (connect(sockfd,
		(struct sockaddr *) &serv_addr,
		sizeof(serv_addr))
	< 0) {
	perror(NULL);
	exit(3);
    }
    
    /* transfer data */
    send_to_speaker(sockfd);
    /*
    fprintf(stderr, "connected\n");
    while ((nread = read(audio_file, buf, SIZE)) > 0) {
	fprintf(stderr, "Writing %d\n", nread);
	write(sockfd, buf, nread);
    }
    close(sockfd);
    close(audio_file);
    */
    exit(0);
}

Speaker cost


Jan Newmarch <jan@newmarch.name>
Last modified: Tue Apr 6 21:08:45 EST 2004
Copyright © Jan Newmarch, Monash University, 2007
Creative Commons License This work is licensed under a Creative Commons License
The moral right of Jan Newmarch to be identified as the author of this page has been asserted.