You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main() {
// socket creation
int network_socket;
network_socket = socket(AF_INET, SOCK_STREAM, 0);
// specify address for socket
struct sockaddr_in server_address;
server_address.sin_family = AF_INET;
server_address.sin_port = htons(9002);
server_address.sin_addr.s_addr = INADDR_ANY;
int connection_status = connect(network_socket, (struct sockaddr*) &server_address, sizeof(server_address));
//check for error with the connection
if (connection_status == -1){
printf("There was an error making a connection to the remote socket \n\n");
// recieve data from server
char server_response[256];
recv(network_socket, &server_response, sizeof(server_response), 0);
// print server's response
printf("The server sent the data: %s\n", server_response);
// close socket
return 0;