-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
28 lines (26 loc) · 752 Bytes
/
client.cpp
File metadata and controls
28 lines (26 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "pch.h"
int main (int argc, char *argv[])
{
int sd; // socket descriptor
struct sockaddr_in server; //socketul plm
char msg[100]; // mesajul trimis
if(argc!=3)
{
printf("[CLIENT] Waiting for <SERVER_ADDRESS>, <PORT>\n");
return -1;
}
int port;
port = atoi(argv[2]); //converting port from input to int
if((sd=socket(AF_INET, SOCK_STREAM,0))==-1)
{
perror("[CLIENT] socket() error.\n");
}
/* gunoaie */
server.sin_family = AF_INET;
server.sin_addr.s_addr = inet_addr(argv[1]);
server.sin_port = htons(port);
if(connect(sd, (struct sockaddr *)&server, sizeof(sockaddr)) == -1){
perror("[CLIENT] connect() error.\n");
}
close(sd);
}