I am facing a problem here.
My program is working. However, I would like to add in some features.
Let see my code first
printf("Address=%s , Port=%s\n", szAddress, szPort);
conn_s=Connect (szPort, szAddress);
printf("Connected to conn_no=%d\n",conn_s);
else //line no. 13
result = strtok(buffer, delims);
if (result == NULL)
if (strcmp(result, "A")==0)
printf("Command: %s\n", result);
map = strtok(NULL, delims);
printf("Map Filename: %s\n", map);
filename = map;
printf("Map Filename: %s\n", filename);
x = strlen(path);
path[x++] = filename[y++];
/*get map and calculate*/
int ** a = alloc_array2d(int, cROW , cCOL );
init_array2d(a, int, cROW , cCOL);
for (r=0; r<cROW; r++) //line no. 47
for (c=0; c< cCOL; c++)
case 0: break;
case 1: break;
// send file error.
printf("file verification error!\n");
When the ethernet network connected, it will go into the else loop at line no. 13. The system will send status and display the status at control panel screen. If at this point, the ethernet disconnected, it will go back to the if loop at line 1. The system will keep trying to connect to the network and keep loop the if loop until it is connected.
Question now is I need the system to test the connection too after going into the operation loop that is start from the line no. 47.
If the system went into the for (int c=0;c<cCOL;c++), it will need to do all the operations as indicated by cCOL times before it exit that loop and go into the previous loop.
I need the system to detect connection everytime an operation is going to happen or ended and if there is no connection, it will trying to connect. Before it is connected, it will not continue the operations.
I tried to put the function "Connect (szPort, szAddress)" into each loop. Yes, the operation stop everytime the network disconnected. However, it shows on control panel screen "New Connection...." everytime it execute the statement. In fact, the network never disconnected.
Is there any suggestion that can solve my problem?
I tried to look at the Connect function code, it is as below, I cannot figure out any statement that can stop the appearance of that "New Connection...". It may be hidden at the library source code, it is too hard for a beginner to modify the library code.
int Connect (char *szPort, char *szAddress)
/* Set the remote port */
int port; /* port number */
int conn_s; /* connection socket */
struct sockaddr_in servaddr; /* socket address structure */
char *endptr; /* for strtol() */
port = strtol(szPort, &endptr, 0);
if ( *endptr )
printf("ECHOCLNT: Invalid port supplied.\n");
if ( (conn_s = socket(AF_INET, SOCK_STREAM, 0)) < 0 )
fprintf(stderr, "ECHOCLNT: Error creating listening socket.\n");
/* Set all bytes in socket address structure to
zero, and fill in the relevant data members */
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(port);
if ( inet_aton(szAddress, &servaddr.sin_addr) <= 0 )
printf("ECHOCLNT: Invalid remote IP address.\n");
/*printf ("%d, %s, %d\n", conn_s, szAddress, port);*/
if (connect(conn_s, (struct sockaddr *) &servaddr, sizeof(servaddr) ) < 0)
printf("ECHOCLNT: Error calling connect()\n");
printf ("%d\n", conn_s);
/* exit(EXIT_FAILURE); */
I hope someone can help me on this.