TCP Callback Client program: main function

Source: Internet
Author: User

Create sockets, reload the internetwork socket address structure

Create a TCP socket, filling an internetwork socket address structure with the server's IP address and port number

We can get the IP address of the server from the command line parameter

Get the server's well-known port number (Serv_port) from the Unp.h file

Connect to Server

Connect to establish a connection to the server

The STR_CLI function completes the remainder of the client processing work

#include "unp.h" intmain (int argc, char **argv) {intsockfd;struct sockaddr_inservaddr;if (argc! = 2) err_quit ("Usage: TCPCLI <IPaddress> "); sockfd = Socket (af_inet, sock_stream, 0); Bzero (&servaddr, sizeof (SERVADDR)); servaddr.sin_family = Af_inet;servaddr.sin_port = Htons (Serv_port); Inet_pton (Af_inet, argv[1], &servaddr.sin_ addr); Connect (SOCKFD, (SA *) &servaddr, sizeof (SERVADDR)), Str_cli (stdin, SOCKFD);/* Do it All */exit (0);}

  

TCP Callback Client program: main function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.