im tryin to send a 2d array in simple socket program..but this only sends the first row and never anything beyond that/….what is the problem here… ?
server part …
struct sockaddr_in clienta,servera;
int s ;
s = socket(AF_INET,SOCK_STREAM,0);
servera.sin_family = AF_INET;
servera.sin_port = htons(3386);
servera.sin_addr.s_addr = htonl(INADDR_ANY);
bind(s,(struct sockaddr *)&servera,sizeof(servera));
listen(s,1);
int news;
int len = sizeof(clienta);
printf("waiting for connection");
news = accept(s,(struct sockaddr *)&clienta , &len);
printf("\n received connection");
int c[3][3];
recv(news, &c,sizeof(c),0);
int d = sizeof(c);
int i=0,j=0;
for(;i<=2;i++)
for(;j<=2;j++)
printf("\n %i,%i,%i",i,j,c[i][j]);
printf("\n %i",c[1][0]);
here is the client program
struct sockaddr_in servera;
int s ;
s = socket(AF_INET,SOCK_STREAM,0);
servera.sin_family = AF_INET;
servera.sin_port = htons(3386);
servera.sin_addr.s_addr = inet_addr("127.0.0.1");
connect(s,(struct sockaddr *)&servera, sizeof(servera));
int b[3][3];
int i=0,j=0;
for(;i<3;i++)
for(;j<3;j++)
b[i][j]=4;
printf("connected");
send(s,&b,sizeof(b),0);
int l = sizeof(b);
You know what these:
and
do?
jis initialized just once (:So, once
jgets3oni = 0, wheni = 1andi = 2jis still3and the secondforis not executed, that’s why you send only the first row.