Skip to content

Instantly share code, notes, and snippets.

@fuzzy
Created December 5, 2016 20:55
Show Gist options
  • Save fuzzy/01dc6d02aef724dd68f388679ca589e1 to your computer and use it in GitHub Desktop.
Save fuzzy/01dc6d02aef724dd68f388679ca589e1 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
void error(const char *msg) {
perror(msg);
exit(0);
}
int main(int argc, char *argv[]) {
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
// get the current time
long ts = time(0);
for (int i = 0; i <= 1000; i++) {
portno = 2003;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
server = gethostbyname("relay-vip.phl.corp.theplatform.com");
if (server == NULL) {
fprintf(stderr,"ERROR, no such host\n");
exit(0);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
error("ERROR connecting");
bzero(buffer,256);
sprintf(buffer, "10s.phl.fuzzy.c-client 1 %ld\n", ts);
fprintf(stderr, "%s", buffer);
n = write(sockfd,buffer,strlen(buffer));
if (n < 0)
error("ERROR writing to socket");
bzero(buffer,256);
n = read(sockfd,buffer,255);
if (n < 0)
error("ERROR reading from socket");
close(sockfd);
sleep(2);
ts = (ts - 10);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment