life is tough, so calm down….

cuma dan hanya menyalurkan hobi gw ^_^

LA Pemprograman Jaringan

ni LA buat hari senin ya..

/* TCPclient.c */
#include <stdio.h>

#include <string.h>

#include <unistd.h>

#include <signal.h>

#include <sys/types.h>

#include <sys/socket.h>

#include <netdb.h>

#include <netinet/in.h>

int main (int argc, char *argv[])

{

struct sockaddr_in alamat_ku;

struct sockaddr_in tujuan;

struct hostent *host_server;

int socketfd, connect_status, baca;

int no_port;

char buffer[256];

if (argc != 3) {

fprintf (stderr, “gunakan: %s <alamat server > <nomor_port>\n”, argv[0]);

exit(1);

}

if ((socketfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {

fprintf (stderr, “tidak bisa memasang socket !\n”);

exit(1);

}

if ((host_server = gethostbyname(argv[1])) == NULL) {

fprintf (stderr, “Nama host mungkin salah :)\n”);

exit(1);

}

no_port = atoi(argv[2]);

bzero (&tujuan, sizeof(tujuan));

tujuan.sin_family = AF_INET;

tujuan.sin_port = htons (no_port);

memcpy ((char *)&tujuan.sin_addr.s_addr, host_server->h_addr_list[0], host_server->h_length);

if ((connect_status = connect (socketfd, (struct sockaddr *)&tujuan, sizeof(tujuan))) < 0) {

fprintf(stderr, “%s: tidak dapat melakukan koneksi\n”, argv[0]);

exit(1);

}

while((baca = recv(socketfd, buffer, strlen(buffer), 0)) > 0) {

printf(“%s”, buffer);

}

close (socketfd);

return 0;

}

Single Post Navigation

2 thoughts on “LA Pemprograman Jaringan

  1. Wew, another spagheti code…. ~!@#$%^&*()

  2. weits mantab mami.. keren keren keren… sapa yg buatin tuh mi???:D

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: