how to pass integer

i am writing a client and server program

client program

main()

{
int sockfd,n;
char str[20];
struct sockaddr_in sock;

if ((sockfd=socket(AF_INET,SOCK_STREAM,0))<0)
{
perror("SOCKET ERROR");
}

bzero(&sock,sizeof(sock));

sock.sin_family=AF_INET;
sock.sin_port=7500;
sock.sin_addr.s_addr=inet_addr("192.127.137.251");

if(connect(sockfd,(struct sockaddr*)&sock,sizeof(sock))<0)
{
perror("CONNECT ERROR :");
}

strcpy(str,"i am here");
write(sockfd,(char *)str,strlrn(str)+1);

//close(sockfd);

socket program

main()
{
int sockfd,connfd,clientlen;
char str[20];
struct sockaddr_in sock,client;

if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0)
{
perror("SOCKET ERROR ");
}

bzero(&sock,sizeof(sock));

sock.sin_family=AF_INET;
sock.sin_port=7500;
sock.sin_addr.s_addr=inet_addr("192.127.137.251");

if((bind(sockfd,(struct sockaddr*)&sock,sizeof(sock)))<0)
{
perror("BIND ERROR:");
}

listen(sockfd,3);

clientlen=sizeof(client);

if((connfd=accept(sockfd,(struct sockaddr*)&client,&clientlen))<0)
{
perror("CONNECTION ERROR :");
}

read(connfd,(char *)str,20);
printf("%s ",str);

close(connfd);
close(sockfd);
}

now the problem is i have to pass a integer or bool variable rather than string
how can i do this

Second argument of write() is pointer to data, you just dont bother what type it is, so to send an int:

write(sockfd, &n, sizeof(n))

will probably send the int value stored in 'n' ...