|
|
then I am working in linux,and I have not config my Chinese input,
and I must encode a web server use C,
and then ,I have a problem ,that is :
I listen the 80 port, and recv someting,
after that ,input http://myname via Firefox
it tell me the "connect is deny" ,so ,I do not know how I can do.
underneath is my code:
- #include <string.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <stdio.h>
- #define MYPORT 80 // the port users will be connecting to
- #define BACKLOG 10 // how many pending connections queue will hold
- int main()
- {
- 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
- int sin_size;
- sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking!
- my_addr.sin_family = AF_INET; // host byte order
- my_addr.sin_port = htons(MYPORT); // short, network byte order
- my_addr.sin_addr.s_addr = INADDR_ANY; // auto-fill with my IP
- memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct
- // don't forget your error checking for these calls:
- bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr));
- listen(sockfd, 5);
- sin_size = sizeof(struct sockaddr_in);
- new_fd = accept(sockfd, (struct sockaddr *)&their_addr, (size_t*)&sin_size);
- char strTemp[1000];
- memset(strTemp,0,1000);
- recv(new_fd,strTemp,1000,0);
- printf("%s\n",strTemp);
- send(new_fd,strTemp,sizeof(strTemp),0);
- return 0;
- }
复制代码
please check it for me,thank you very much! |
|