im just creating an client that is going to communicated with Iterative server.
and i get this error:
warning: the `gets' function is dangerous and should not be used.
and i think this is related to this code:
printf("Enter message to be sent:\n");
gets(send_buf);
and this is my code for the client could anyone could check it to see if am on the right track:
Expand|Select|Wrap|Line Numbers
- /**************************************************************************/
- /* Generic client example is used with connection-oriented server designs */
- /**************************************************************************/
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <string.h>
- #define EOB "$$"
- #define KB_size 1024
- int ClientNo = 0;
- main (int argc, char *argv[])
- {
- int len, rc;
- int sockfd;
- char send_buf[80];
- char recv_buf[80];
- char KB_buff[KB_size];
- int intPort;
- struct sockaddr_in addr;
- /*************************************************/
- /* Create an AF_INET stream socket */
- /*************************************************/
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd < 0)
- {
- perror("socket");
- exit(-1);
- }
- /*************************************************/
- /* Initialize the socket address structure */
- /*************************************************/
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr.s_addr = htonl(INADDR_ANY);
- addr.sin_port = htons(intPort);
- /*************************************************/
- /* Connect to the server */
- /*************************************************/
- rc = connect(sockfd,(struct sockaddr *)&addr, sizeof(struct sockaddr_in));
- if (rc < 0)
- {
- perror("connect");
- close(sockfd);
- exit(-1);
- }
- printf("Connect completed.\n");
- /*************************************************/
- /* Enter data buffer that is to be sent */
- /*************************************************/
- printf("Enter message to be sent:\n");
- gets(send_buf);
- /*************************************************/
- /* Send data buffer to the worker job */
- /*************************************************/
- len = send(sockfd, send_buf, strlen(send_buf) + 1, 0);
- if (len != strlen(send_buf) + 1)
- {
- perror("send");
- close(sockfd);
- exit(-1);
- }
- printf("%d bytes sent\n", len);
- /*************************************************/
- /* Receive data buffer from the worker job */
- /*************************************************/
- len = recv(sockfd, recv_buf, sizeof(recv_buf), 0);
- if (len != strlen(send_buf) + 1)
- {
- perror("recv");
- close(sockfd);
- exit(-1);
- }
- printf("%d bytes received\n", len);
- /*************************************************/
- /* Close down the socket */
- /*************************************************/
- close(sockfd);
- }