第一个程序,当然是向世界问好。
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
int main()
{
int sockfd;
int len,chlen;
int ii=0;
struct sockaddr_in address;
int result;
char ch[] = {0x68,0x17,0x07,0x00,0x19,0x00,0x00,0x1c,0x01,0x01,0xe6,0x02,0x01,0xde,0x04,0x01,0x90,0x05,0x01,0x8e,0x21,0x21,0x92,0x28,0xed,0x9a,0x29,0xfd,0x81,0x24,0x00,0x16,0x12,0x06,0x05,0x08,0x7b,0x16,0x00};
//char ch='A';
//char* msg = "Hello, world!";
chlen = 38;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
address.sin_family = AF_INET;
address.sin_addr.s_addr = inet_addr("192.168.1.3");
address.sin_port = htons(6429);
len = sizeof(address);
result = connect(sockfd, (struct sockaddr *)&address, len);
if (result == -1) {
perror("oops: client/n");
//exit();
}
//write(sockfd, &ch, 1);
//read(sockfd, &ch, 1);
//printf("char from server = %c/n", ch);
//len = strlen(msg);
for (ii=0; ii<500; ii++) {
//result = send(sockfd, msg, len, 0);
//printf("sent (%d): %s/n", result, msg);
//sleep(10);
result = send(sockfd, ch, chlen, 0);
printf("sent (%x): %s/n", result, ch);
sleep(10);
}
close(sockfd);
exit(1);
}
以及它的Makefile
CC = /usr/local/arm-linux/bin/arm-linux-gcc
CFLAGS = -I/usr/local/kernel_2410tk/include -I/usr/local/kernel_2410tk/include/asm-arm -I/usr/local/kernel_2410tk/arch/arm
client: client.c
$(CC) $(CFLAGS) -o client client.c -lpthread -DLINUX -D_REENTRANT -Os -ffixed-r8 -mshort-load-bytes -mapcs-32 -march=armv4 -mtune=arm9tdmi
clean:
-rm -f *.o