Hi All,
I've write a code for client and server. It works well so far but the server just acknowledge the client of what it received. How to recode this program to make sure that once server acknowledged the client that the data sent by the client have been append in the file in the server machine so that client program can update the status of that particluar MySQL table? I've write the code but the status didnt update as what I want and I also cant compile this program. The error is: client.c:65: error: incompatible types in assignment
Below are the code:
#include <mysql.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
void error(char *msg)
{
perror(msg);
exit(0);
}
int main(int argc, char *argv[])
{
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *host = "192.168.2.11";
char *user = "daily1a";
char *password = "daily2006";
char *database = "28882db";
char string1[500], query[500], Tid[50];
void senddata(char *SendString);
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, host,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(0);
}
/* send SQL query */
if (mysql_query(conn, "SELECT MobileNumber, StartDate, EndDate FROM Subscriptions where Status=0")) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(0);
}
res = mysql_use_result(conn);
/* output fields 0, 1 and 2 of each row */
while ((row = mysql_fetch_row(res)) != NULL)
{
bzero(string1, sizeof(string1));
sprintf(string1,"%s,%s,%s", row[0], row[1], row[2]);
printf ("%s\n",string1);
senddata(string1);
}
if (row[9]==0)
{
bzero(query, sizeof(query));
Tid = atoi(row[0]);
sprintf(query, "UPDATE Subscriptions SET Status = 1 WHERE MobileNumber = '%s'",Tid);
}
/* Release memory used to store results and close connection */
mysql_free_result(res);
mysql_close(conn);
return 0;
}
void senddata(char *SendString)
{
char buf[8192];
char message[256];
int socket_descriptor;
struct sockaddr_in pin;
struct hostent *server_host_name;
char * host_name = "127.0.0.1";
int port = 8000;
char * str = "A default test string";
str = SendString;
if ((server_host_name = gethostbyname(host_name)) == 0) {
perror("Error resolving local host\n");
exit(1);
}
bzero(&pin, sizeof(pin));
pin.sin_family = AF_INET;
pin.sin_addr.s_addr = htonl(INADDR_ANY);
pin.sin_addr.s_addr = ((struct in_addr *)(server_host_name->h_addr))->s_addr;
pin.sin_port = htons(port);
if ((socket_descriptor = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("Error opening socket\n");
exit(1);
}
if (connect(socket_descriptor, (void *)&pin, sizeof(pin)) == -1) {
perror("Error connecting to socket\n");
exit(1);
}
printf("Sending message %s to server...\n", str);
if (send(socket_descriptor, str, strlen(str), 0) == -1) {
perror("Error in send\n");
exit(1);
}
printf("...Sent message.. wait for response...\n");
if (recv(socket_descriptor, buf, 8192, 0) == -1) {
perror("Error in receiving response from server\n");
exit(1);
}
printf("\nResponse from server:\n\n%s\n", buf);
close(socket_descriptor);
}
Need any help from expert here..thanks