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));
	
		}

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.