接收到信号:信号管(断管) 我在C++上创建了一个简单的客户机/服务器多人游戏。因此,当我尝试发送smth时,客户端成功连接。对于它,我从调试器中得到以下消息“接收到的信号:SIGPIPE(断管)” 代码如下:
服务器:接收到信号:信号管(断管) 我在C++上创建了一个简单的客户机/服务器多人游戏。因此,当我尝试发送smth时,客户端成功连接。对于它,我从调试器中得到以下消息“接收到的信号:SIGPIPE(断管)” 代码如下:,c++,sockets,broken-pipe,C++,Sockets,Broken Pipe,服务器: string _ip = "127.0.0.1"; sockaddr_in _tempFullAddress; int _templistener; int _tempPort; int mes = 27; _tempFullAddress.sin_family = AF_INET; _tempFullAddress.sin_port = 5326; inet_aton(_ip.c_str(), &(_tempF
string _ip = "127.0.0.1";
sockaddr_in _tempFullAddress;
int _templistener;
int _tempPort;
int mes = 27;
_tempFullAddress.sin_family = AF_INET;
_tempFullAddress.sin_port = 5326;
inet_aton(_ip.c_str(), &(_tempFullAddress.sin_addr));
_templistener = socket(AF_INET, SOCK_STREAM, 0);
int bindResult =
bind(_templistener, (sockaddr*) &_tempFullAddress, sizeof(_tempFullAddress));
if (bindResult<0){
cout<<"Error on binding\n";
return 0;
}
listen(_templistener, 1);
char buf[1];
buf[0]=(char)mes;
accept(_templistener, NULL, NULL);
send(_templistener, buf, 1, 0);
close(_templistener);
客户端成功连接,但未接收任何内容。您无法在侦听套接字上发送数据
accept
返回表示连接的新套接字,然后发送该连接上的数据
int _tempconn = accept(_templistener, NULL, NULL);
send(_tempconn, buf, 1, 0);
close(_tempconn);
close(_templistener);
int _tempconn = accept(_templistener, NULL, NULL);
send(_tempconn, buf, 1, 0);
close(_tempconn);
close(_templistener);