mirror of
https://github.com/ada-dmitry/prog.l_ada.git
synced 2026-09-24 09:10:14 +00:00
s
This commit is contained in:
@@ -10,48 +10,55 @@
|
||||
//./client_app stud*** "port"
|
||||
|
||||
#define DATA "Hello, World!"
|
||||
|
||||
int main(int argc, char *argv[]){
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int sock;
|
||||
struct sockaddr_in server;
|
||||
struct hostent *hp;
|
||||
char buf[1024];
|
||||
|
||||
if (argc < 3) {
|
||||
printf("c_inet hostname port [data]\n");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
if((sock = socket( AF_INET, SOCK_STREAM, 0)) == -1) {
|
||||
perror("opening stream socket");
|
||||
exit(1);
|
||||
if (argc < 3)
|
||||
{
|
||||
printf("c_inet hostname port [data]\n");
|
||||
_exit(1);
|
||||
}
|
||||
|
||||
hp=malloc(sizeof(struct hostent));
|
||||
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1)
|
||||
{
|
||||
perror("opening stream socket");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
hp = malloc(sizeof(struct hostent));
|
||||
|
||||
server.sin_family = AF_INET;
|
||||
hp = gethostbyname(argv[1]);
|
||||
if (hp == (struct hostent *) 0) {
|
||||
fprintf(stderr, "%s: unknown host\n", argv[1]);
|
||||
exit(2);
|
||||
if (hp == (struct hostent *)0)
|
||||
{
|
||||
fprintf(stderr, "%s: unknown host\n", argv[1]);
|
||||
exit(2);
|
||||
}
|
||||
memcpy((char *) &server.sin_addr, (char *) hp->h_addr, hp->h_length);
|
||||
memcpy((char *)&server.sin_addr, (char *)hp->h_addr, hp->h_length);
|
||||
server.sin_port = htons(atoi(argv[2]));
|
||||
if (connect(sock, (struct sockaddr *) &server, sizeof server) == -1) {
|
||||
if (connect(sock, (struct sockaddr *)&server, sizeof server) == -1)
|
||||
{
|
||||
perror("connecting stream socket");
|
||||
exit(1);
|
||||
}
|
||||
getchar();
|
||||
memset(buf,0,1024);
|
||||
if (argc > 3){
|
||||
printf("[%s]\n",argv[3]);
|
||||
strcpy(buf,argv[3]);
|
||||
}else{
|
||||
strcpy(buf,DATA);
|
||||
memset(buf, 0, 1024);
|
||||
if (argc > 3)
|
||||
{
|
||||
printf("[%s]\n", argv[3]);
|
||||
strcpy(buf, argv[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(buf, DATA);
|
||||
}
|
||||
if (write(sock, buf, strlen(buf)) == -1)
|
||||
perror("writing on stream socket");
|
||||
perror("writing on stream socket");
|
||||
close(sock);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user