客戶端如何指定端口?
和服務器綁定端口一樣,只是一般客戶端不需要綁定端口。java應該也可以 struct sockaddr_in clientAddr; clientAddr.sin_family = AF_INET; clientAddr.sin_port = htons(6666)
; clientAddr.sin_addr.S_un.S_addr = 0; bind(sockClient, (struct sockaddr*)&clientAddr, sizeof(clientAddr));