我爲服務器實現編寫的代碼不工作。 程序錯誤bind()
套接字地址正確並生成錯誤。套接字編程,bind()錯誤
代碼
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<string.h>
#include<stdlib.h>
#include <netdb.h>
int main(int argc , char* argv[])
{
int socket_descriptor;
struct sockaddr_in server;
char buffer[512];
int rval;
int socket_a;
if(socket_descriptor = socket(AF_INET, SOCK_STREAM , 0) < 0)
{
perror("Error at creating the socket");
exit(1);
}
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(5000);
if(bind(socket_descriptor,(struct sockaddr *)&server,sizeof(server)) < 0)
{
perror("Error at binding");
exit(1);
}
}
錯誤
錯誤的結合:對非套接字套接字操作。
使用這些[代碼](http://www.cs.rpi.edu/~moorthy/Courses/os98/Pgms/ socket.html) – EsmaeelE