how to pass integer


 
Thread Tools Search this Thread
Special Forums IP Networking how to pass integer
# 1  
Old 08-25-2005
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
# 2  
Old 08-25-2005
Second argument of write() is pointer to data, you just dont bother what type it is, so to send an int:
Code:
write(sockfd, &n, sizeof(n))

will probably send the int value stored in 'n' ...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Are These All The Integer Types In C

Hello and Good day, I am currently studying C and I just finished learning about variables mainly those of integer type. I am wondering if the list below are all there is to integer variables and there are still more that i have to learn. Here are the list: Char Short int long long long... (3 Replies)
Discussion started by: split_func0
3 Replies

2. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

3. Shell Programming and Scripting

Convert to Integer

Hi fellows!! i'm doing something which is not working out for me properly which i don't understand why nowdate=`date +%s` echo $nowdate now the problem how to convert a date which is stored in a variable mydate="22/Oct/2011" mydate=`date -d '$mydate' +%s` it gives error... (11 Replies)
Discussion started by: me_newbie
11 Replies

4. Solaris

How to Use a Variable as Integer?

hello, i am writing a script that takes the UID from the PASSWD and then i want to increse the Number by one. for the Next user. i cannot get this to work that a variable is as interger example: set i = 0 set $i = $+1 it's in tcsh if it's mather (10 Replies)
Discussion started by: shatztal
10 Replies

5. Shell Programming and Scripting

Alphanumeric to integer

Hi folks, I have a value like A12,i could able to change this into integer using typeset as below typeset -i A12 But, I need your advice to change the values like 1A2 or 12A into integer. Thanks in advance. Thanks, Sathish (3 Replies)
Discussion started by: bsathishmca
3 Replies

6. UNIX for Dummies Questions & Answers

integer to string

Hi all, is there an easy way to convert integer to string in bash? I have numbers like 1, 2, ..., 112, ... and I would like to get 001 002 003 004 ... Thank you, Sarah (4 Replies)
Discussion started by: f_o_555
4 Replies

7. Shell Programming and Scripting

reverse an integer

i have created a script that will reverse any given ineter. #!/bin/ksh echo "Enter the number" read n if then a=`expr $n / 10` b=`expr $n % 10` c=`expr $b \* 10 + $a` fi echo $c --------------------------------------------------------------------- the problem with this script... (4 Replies)
Discussion started by: ali560045
4 Replies

8. Shell Programming and Scripting

Cannot store integer value

Hi , I have code like below in my ksh script, but getting an error as SP2-0253: data item 1 ("SAMPLE_ID") will not fit on line , pls help me. thanks. if (( CHECKS == 0 )) || (( CHECKS == 1 )) then V_SAMPLE_ID=$( $ORACLE_HOME/bin/sqlplus -S / <<EOF whenever sqlerror exit 1... (5 Replies)
Discussion started by: bennichan
5 Replies

9. Shell Programming and Scripting

get integer part

Hi, I did a df|awk| command and it returns a percentage "94%", how could I only get the integer part "94" out of it, so I can compare it to another number, I knwo that I have to pipe it to sth, but "grep " did not work, it still give me number WITH the percentage, does someone know what... (3 Replies)
Discussion started by: ericaworld
3 Replies

10. UNIX for Advanced & Expert Users

pf not working properly even with only "pass in all" and "pass out all" rules

i have two rules in my pf.conf file, "pass in all" and "pass out all" i was having issues with getting pf working to begin with, so i went with starting from nothing and working on up. i have an ultrasparc ultra1 200e, with an added 4-port fast ethernet sbus card, running "3.4 GENERIC#85... (4 Replies)
Discussion started by: xyyz
4 Replies
Login or Register to Ask a Question