0

hi

following i a code that calculates systems up time in days, hrs, min, sec
after calculation result is sent to client. but through this code we can only send any one paramter mean either day, hrs, min or sec. as a result of this code we get on client side 'days' only.

but i want to send all 4 (days, hrs,min, sec) to client.

int systm_time()
		{	
		char send_data[1024];
		if(sysinfo(&sys_info) != 0)
		    perror("sysinfo");
		 
		  // Uptime
		  days = sys_info.uptime / 86400;
		  hours = (sys_info.uptime / 3600) - (days * 24);
		  mins = (sys_info.uptime / 60) - (days * 1440) - (hours * 60);
		// on server window we get the result 
		  printf("Uptime: %ddays, %dhours, %dminutes, %ldseconds\n",
		                      days, hours, mins, sys_info.uptime % 60);
		
              // this function is used to convert int to char str
               sprintf(send_data,"%ddays", days);	
		// result of days is saved in send_data is beign passed to client through                                                       sendto()
		sendto(sock, send_data, strlen(send_data), 0,
	              (struct sockaddr *)&client_addr, sizeof(struct sockaddr));
	
		}
2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by nbaztec
0

but i want to send all 4 (days, hrs,min, sec) to client.

Make a data packet & send. It shouldn't be difficult at all.

0

how to create data packet?
i m doing socket programming fro the first time so have no knowledge :-(

in my above code on line 16.. days are passed in send_data. and send_data is passes as an argument of sendto().

i need hs, mins and sec also to be sent in sendto() along days

0

I meant create your OWN data packet. Set a limit of char array say 4bytes with 10bytes each for days,hr,min & seconds. then send it. & read the data again. Use a class it should be easy.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.