beautypg.com

Solvline PB2xxxUG User Manual

Page 103

background image

}

//Creates the socket.

if ((sock = socket(PF_INET, SOCK_STREAM, 0))<0)

{

printf("cant open socket!!\n");

exit(0);

}

bzero((char *)&server_addr, sizeof(server_addr));

//Fills the structure.

server_addr.sin_family = AF_INET;

server_addr.sin_addr.s_addr = inet_addr(argv[1]);

server_addr.sin_port = htons(4001);

//Connects to the server.

if (connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0)

{

printf("cant connect to server!!\n");

exit(0);

}

while(1)

{

SendData();

sleep(3);

GetData();

}

close(sock);

}

//Creates the data packet to transmit it to the server.

void SendData(void)

{

int i;

char temp[30] = "This is LoopBack Data !";

// Outputs data with the socket number 4001 of Porter.

write(sock, temp, sizeof(temp));

}

103