2013-07-21 3 views
0

C++에서 간단한 클라이언트/서버 멀티 플레이어 게임을 만들고 있습니다. 그래서 클라이언트가 성공적으로 연결됩니다. 여기에, 내가 디버거에서이 메시지가 "신호가 수신 : SIGPIPE (브로큰 파이프)"받은 신호 : SIGPIPE (깨진 파이프)

서버 :

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); 

가 클라이언트 :

sockaddr_in _tempServerAddress; 
    int _tempServerPort=5326; 
    int _tempSocket; 
    char buf[1]; 
    string _serverIp=""127.0.0.1"; 

    _tempServerAddress.sin_family=AF_INET; 
    _tempServerAddress.sin_port=_tempServerPort; 
    inet_aton(_serverIp.c_str(), &(_tempServerAddress.sin_addr)); 
    _tempSocket=socket(AF_INET, SOCK_STREAM, 0); 

    connect(_tempSocket, (sockaddr*)&_tempServerAddress, sizeof(_tempServerAddress)); 

    recv(_tempSocket, buf, 1, 0); 
    _serverPort=5300+((int)buf[0]-'0'); 

클라이언트가 성공적으로 연결 여기 코드입니다 , 아무 것도받지 못합니다.

답변

1

청취 소켓에서 데이터를 보낼 수 없습니다. accept은 연결을 나타내는 새 소켓을 반환하고 해당 연결에서 데이터를 보냅니다.

int _tempconn = accept(_templistener, NULL, NULL); 
send(_tempconn, buf, 1, 0); 

close(_tempconn); 
close(_templistener); 
+0

감사합니다. – leoUA