N
nick048
Hi to all,
I have written a little Server program in C and I have compiled this
with Cygwin without errors. This is my code:
// Prototype
void wordReceived(int sd,char *s);
int main (unsigned argc, char **argv) {
int SERVER_PORT, sock, client_len, fd;
struct sockaddr_in server, client;
char *theword;
..
.. <OTHER CODE>
..
wordReceived(fd,theword); /* Process the word received from
client*/
..
.. <OTHER CODE>
..
}
void wordReceived(int sd,char *s){
int i=0;
int charRecv = 0;
char c[1];
charRecv = recv(sd, c, 1, 0);
while (c[1] !='\n'){
s[i++]=c[1];
charRecv = recv(sd, c, 1, 0);
} // End while (c !='\n')
s='\0';
}
When the program call wordReceived, Cygwin return to me this message:
"5 [main] myserver 2736 _cygtls:: handle_exception: Error while
dumping state (probably corrupted stack)"
and the program hang.
I have modified my program in this way:
int main (unsigned argc, char **argv) {
int SERVER_PORT, sock, client_len, fd;
struct sockaddr_in server, client;
char theword[30];
char c;
int i, charRecv;
..
.. <OTHER CODE>
..
i=0;
charRecv = recv(fd, &c, 1, 0);
while (c !='\n')
{
theword[i++]=c;
charRecv = recv(fd, &c, 1, 0);
} // End while (c !='\n')
theword='\0';
..
.. <OTHER CODE>
..
}
In this way the program run fine.
Wich is my error in the first program ?
How can modify my code in order to use correctly wordReceived?
I hope in Your help in order to resolve my little problem
Thank You and Best Regards
Nick
I have written a little Server program in C and I have compiled this
with Cygwin without errors. This is my code:
// Prototype
void wordReceived(int sd,char *s);
int main (unsigned argc, char **argv) {
int SERVER_PORT, sock, client_len, fd;
struct sockaddr_in server, client;
char *theword;
..
.. <OTHER CODE>
..
wordReceived(fd,theword); /* Process the word received from
client*/
..
.. <OTHER CODE>
..
}
void wordReceived(int sd,char *s){
int i=0;
int charRecv = 0;
char c[1];
charRecv = recv(sd, c, 1, 0);
while (c[1] !='\n'){
s[i++]=c[1];
charRecv = recv(sd, c, 1, 0);
} // End while (c !='\n')
s='\0';
}
When the program call wordReceived, Cygwin return to me this message:
"5 [main] myserver 2736 _cygtls:: handle_exception: Error while
dumping state (probably corrupted stack)"
and the program hang.
I have modified my program in this way:
int main (unsigned argc, char **argv) {
int SERVER_PORT, sock, client_len, fd;
struct sockaddr_in server, client;
char theword[30];
char c;
int i, charRecv;
..
.. <OTHER CODE>
..
i=0;
charRecv = recv(fd, &c, 1, 0);
while (c !='\n')
{
theword[i++]=c;
charRecv = recv(fd, &c, 1, 0);
} // End while (c !='\n')
theword='\0';
..
.. <OTHER CODE>
..
}
In this way the program run fine.
Wich is my error in the first program ?
How can modify my code in order to use correctly wordReceived?
I hope in Your help in order to resolve my little problem
Thank You and Best Regards
Nick