小编Abj*_*a22的帖子

C套接字编程没有输入端口

我正在尝试为C套接字编程中没有输入端口时设置默认端口号.有谁知道我怎么做到这一点?我一直在尝试分段错误.

码:

#define PORT 12345

int main(int argc, char *argv[]) {

    /* Thread and thread attributes */
    pthread_t client_thread;
    pthread_attr_t attr;


    int sockfd, new_fd;  /* listen on sock_fd, new connection on new_fd */
    struct sockaddr_in my_addr;    /* my address information */
    struct sockaddr_in their_addr; /* connector's address information */
    socklen_t sin_size;
    int i=0;

    /* Get port number for server to listen on */
    if (argc != 2) {
        fprintf(stderr,"usage: client port_number\n");
        exit(1);
    }

    /* generate the socket */
    if ((sockfd …
Run Code Online (Sandbox Code Playgroud)

c sockets connection port numbers

-2
推荐指数
1
解决办法
58
查看次数

标签 统计

c ×1

connection ×1

numbers ×1

port ×1

sockets ×1