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