Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Created January 31, 2014 12:53
Show Gist options
  • Save kotaroito/8731600 to your computer and use it in GitHub Desktop.
Save kotaroito/8731600 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
int main(int argc, char* argv[])
{
int fd;
struct sockaddr_in addr;
// create socket
if ( (fd = socket(PF_INET, SOCK_STREAM, 0)) < 0 ) {
perror("socket");
exit(EXIT_FAILURE);
}
// connect to server
memset(&addr, 0, sizeof(addr));
addr.sin_family = PF_INET;
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
addr.sin_port = htons(8983);
if ( connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0 ) {
perror("connect");
exit(EXIT_FAILURE);
}
sleep(1);
// close
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment