// SocketClient.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include "stdafx.h"
#include "ClientSocket.h"
using namespace sock;
int _tmain(int argc, _TCHAR* argv[])
{
try
{
ClientSocket client_socket ( "127.0.0.1", 30000 );
try
{
while (true)
{
std::string aaa;
std::cin >> aaa;
if (aaa == "quit")
{
break;
}
/*
for (int i = 0; i < 10000; i++)
{
aaa += "Test message";
}
//*/
client_socket << aaa;
std::cout << "send : " << aaa << std::endl;
std::cout << "send size : " << aaa.size() << std::endl;
std::string reply;
client_socket >> reply;
std::cout << "receive : " << reply << std::endl;
std::cout << "receive size: " << reply.size() << std::endl;
std::cout << "We received this response from the server:/n/"" << reply << "/"/n";
}
}
catch ( SocketException& e)
{
std::cout << e.What() << std::endl;
}
}
catch ( SocketException& e )
{
std::cout << "Exception was caught:" << e.What() << "/n";
}
getchar();
return 0;
}
// SocketServer.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include "stdafx.h"
#include "ServerSocket.h"
using namespace sock;
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "running..../n";
try
{
// Create the socket
ServerSocket server ( 30000 );
while ( true )
{
ServerSocket newSock;
server.Accept(newSock);
// ServerSocket newSock = server.Accept();
std::cout << "new socket" << std::endl;
std::cout << "ip: " << newSock.GetIp() << " /t port:" << newSock.GetPort() << std::endl;
try
{
while ( true )
{
std::string data;
newSock >> data;
/*if (newSock.Recv(data) < 0)
{
break;
}*/
std::cout << "receive : " << data << std::endl;
std::cout << "receive size : " << data.size() << std::endl;
if (data.size() == 0)
{
break;
}
newSock << "you send data is : "+ data;
}
}
catch ( SocketException& e)
{
std::cout << e.what() << std::endl;
}
}
}
catch ( SocketException& e )
{
std::cout << "Exception was caught:" << e.What() << "/nExiting./n";
}
return 0;
}