hey.. can ny1 help me in linking the client n server in c++
here this is a prog for client test
Code:
using namespace jmp_tcp;
int main (int argc, char * const argv[]) {
TcpClient client;
if(!client.connectByName("localhost", 8000))
{
std::cout << std::endl << "client connection failed"<< std::endl;
return 0;
}
std::string msg;
char buff[256];
while(msg != "by")
{
std::cin >> msg;
if(msg.length() >0)
{
bzero((char *) buff, sizeof(buff));
if (!client.send(msg.c_str(), msg.length()))
{
std::cout<< std::endl << "send error";
break;
}
int len = client.read(buff, sizeof(buff));
std::cout << std::endl << len << " " << buff << std::endl;
if (len <=0) break;
else
{
std::cout << std::endl << len << " " << buff << std::endl;
}
}
}
client.disconnect();
return 0;
}
n now i have to send a function
d->asyncEvent.printOn(std::cout); to the server..
how can i do dis..
and dis is the server part
#include <iostream>
#include "jmp_tcp/TcpServer.h"
#include "3d_connexion_poc/Protocol.h"
#include "cfsocket/CFTcpServer.h"
using namespace jmp_tcp;
class ServerTest : public TcpServer
{
protected:
virtual void handleConnection(int cfd)
{
char buff[256];
std::cout << "handles a new connection" << std::endl;
while(true)
{
std::cout << " new read " << std::endl;
bzero((char *) buff, sizeof(buff));
int length = recv(cfd, buff, sizeof(buff), 0);
std::cout << " length " << length << std::endl;
if (length <=0) break;
else
{
send(cfd, buff, length, 0);
std::cout << buff << std::endl;
if (strcmp(buff, "by")==0) break;
}
}
std::cout << "terminate a connection" << std::endl;
}
};
void dynamicPort()
{
ServerTest server;
int port = 8000;
while(!server.setup(port) && port <9000)
{
std::cout << std::endl << "server setup failed for port "<< port << std::endl;
port++;
}
std::cout << std::endl << "server running" << std::endl;
server.acceptConnections();
}
void staticPort()
{
ServerTest server;
int port = 8000;
if(!server.setup(port))
{
std::cout << std::endl << "server setup failed"<< std::endl;
return;
}
std::cout << std::endl << "server running" << std::endl;
server.acceptConnections();
}
void testProtocol()
{
Protocol<int> p;
p.setElementValue("x", 10);
p.setElementValue("y", 23);
p.setElementValue("z",544);
p.printOn(std::cout << std::endl);
int length=0;
const char* frame = p.getBuffer(length);
p.setBuffer(frame, length);
p.printOn(std::cout << std::endl);
}
void testCFTcpServer()
{
CFTcpServer server;
int port = 8000;
if(!server.setup(port))
{
std::cout << std::endl << "server setup failed"<< std::endl;
return;
}
std::cout << std::endl << "server running"<< std::endl;
CFRunLoopRun();
}
int main (int argc, char * const argv[])
{
//staticPort();
//dynamicPort();
//testProtocol();
testCFTcpServer();
return 0;
}
... plzzz help me if u can..