PDA

Visualizza la versione completa : [C++] Problema Socket?


return
23-05-2014, 21:31
Salve a tutti ragazzi, ho un problema con l'accettare la connessione socket :


Server.h
#ifndef Server_H
#define Server_H


#include <winsock.h>


#pragma comment (lib, "wsock32.lib")
namespace Server
{
class Server_s
{
public:
WSAData wsa;
WORD word;
SOCKET Connect,Listen;
sockaddr_in sock;
int Start_Server();
int port;
char* ip;
Server_s()
{
ip = "127.0.0.1";
port=4003;
word = MAKEWORD(2,1);
Connect=socket(2,1,0);
Listen=Connect;
sock.sin_addr.s_addr=inet_addr(ip),sock.sin_family =2,sock.sin_port=htons(port);
}
};
}
#endif




//Server.cpp
#include "Server.h"
#include <iostream>
namespace Server
{
int Server_s::Start_Server()
{
WSAStartup(word,&wsa);
bind(Listen,(sockaddr*)&sock,sizeof(sock));
int listen_start=listen(Listen,1);
int size =sizeof(sock);
while(listen_start==0){
Connect=accept(Listen,(sockaddr*)&sock,&size);
std::cout<<"Start() - > Recv Connection : "<<ip<<" "<<port<<std::endl;
std::string session_in = "Welcome"
send(Connect,session_in.c_str(),session_in.size(), 0);}
return 0;
}
}

Ed infine il main :


#include "Server.h"
#include <iostream>
#define PORT 4003
#define s_c std::cout
#define s_e std::endl
int main()
{
Server::Server_s *s_Start;
s_Start=new Server::Server_s;
system("title Welcome");
s_c<<"Benvenuto nel Server!-!<<s_e;

s_Start->Start_Server();


WSACleanup();
getchar();
}

maluz1
24-05-2014, 14:56
qual l'errore che ricevi?

Loading