- 论坛徽章:
- 0
|
linux debug 求助
#include <string.h>;
#include <netdb.h>;
#include <sys/types.h>;
#include <netinet/in.h>;
#include <sys/socket.h>;
#include <stdio.h>;
int main(int argc, char* argv[])
{
int sockfd, numbytes;
struct sockaddr_in their_addr; /* connector's address information */
if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("socket failed\n" ;
exit(1);
}
bzero(&their_addr, sizeof(their_addr)); /* zero the rest of the struct */
their_addr.sin_family = AF_INET; /* host byte order */
their_addr.sin_port = htons(7000); /* short, network byte order */
printf("----0003--------\n" ;
// their_addr.sin_addr.s_addr = inet_addr("192.168.181.8" ;
inet_pton(PF_INET, "192.168.181.8", &their_addr.sin_addr);
printf("-------hhhh-----%d\n", sockfd);
if(connect(sockfd, (struct sockaddr*)&their_addr, sizeof(their_addr)) == -1)
{
printf("----disconnect----\n" ;
printf("----1111---\n" ;
exit(1);
}
{
printf("<>; - 1\n" ;
}
printf("----2222-----\n" ;
if (send(sockfd, "hello", 6, 0) <= 0)
{
printf("----send----\n" ;
exit(1);
}
close(sockfd);
return 0;
}
编译信息
[gaozh@PDC ~]$ make
gcc client.c -o client
[gaozh@PDC ~]$ ./client
----0003--------
-------hhhh-----3
----disconnect----
----1111--- |
|