0
sry但我的英語。C++多客戶端服務器
這是用C++編寫 一個簡單的應用程序客戶端 - 服務器操作系統的OpenSUSE 13.1的Linux
我不知道該怎麼辦的多客戶端 如果你能幫助我,我將不勝感激多
所有這是工作,只有一個客戶端
我需要幫助,感謝
這是 Server.cpp
#include "ServerSocket.cpp"
#include "SocketException.h"
#include <string>
#include <iostream>
int main()
{
std::cout << "running....\n";
try
{
// Create the socket
ServerSocket server (2020);
while (true)
{
ServerSocket new_sock;
server.accept (new_sock);
try
{
while (true)
{
std::string data;
new_sock >> data;
std::cout << "in::" << data << std::endl;
new_sock << data; // Respuesta
}
}
catch (SocketException&) {}
}
}
catch (SocketException& e)
{
std::cout << "Exception was caught:" << e.description() << "\nExiting.\n";
}
return 0;
}
這是 Client.cpp
#include "ClientSocket.cpp"
#include "SocketException.h"
#include <iostream>
#include <string>
int main ()
{
try
{
ClientSocket client_socket ("localhost", 2020);
std::string reply;
try
{
std::string Envio = "";
while(Envio != "Exit")
{
getline(std::cin, Envio);
client_socket << Envio;
client_socket >> reply;
}
}
catch (SocketException&) {}
std::cout << "We received this response from the server:\n\"" << reply << "\"\n";;
}
catch (SocketException& e)
{
std::cout << "Exception was caught:" << e.description() << "\n";
}
return 0;
}