28 lines
935 B
C
28 lines
935 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include<string.h> //strlen
|
|
#include<sys/socket.h>
|
|
#include<arpa/inet.h> //inet_addr
|
|
#include<unistd.h> //write
|
|
#include<netdb.h>
|
|
|
|
struct sockaddr_in sa ;
|
|
int main()
|
|
{ int err;
|
|
char my_buf[1024] ;
|
|
char *msg = "I am your main socket squeeze" ;
|
|
|
|
int my_sock = socket(AF_INET, SOCK_STREAM, 0) ;
|
|
sa.sin_family = AF_INET ;
|
|
sa.sin_port = htons(10059) ;
|
|
inet_pton(AF_INET, "130.111.216.48" , &(sa.sin_addr)) ;
|
|
printf("BEFOrE CONNECT\n") ;
|
|
int x = connect(my_sock, (struct sockaddr *) &sa, sizeof(sa)) ;
|
|
perror("Connect") ;
|
|
|
|
printf ("Sending Message to Server!\n") ;
|
|
send (my_sock, msg, 32, 0) ;
|
|
printf ("Receiving Message from Server!\n") ;
|
|
int recv_size = recv(my_sock , my_buf , 32 , 0) ;
|
|
printf("Here is the message: \n%s\n", my_buf) ;
|
|
} |