Thread: Client server programming hijack

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    Client server programming hijack

    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..

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    1. Read the forum rules about hijacking old threads.

    2. Read the forum RULES about using code tags.

    3. Learn to write English, not kiddie script on a broken keyboard.
    How To Ask Questions The Smart Way
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory Leak in AppWizard-Generated Code
    By jrohde in forum Windows Programming
    Replies: 4
    Last Post: 05-19-2010, 04:24 PM
  2. server client application - (i really need your help)
    By sarahnetworking in forum C Programming
    Replies: 3
    Last Post: 03-01-2008, 10:54 PM
  3. Client works on a LAN but don't send all the data
    By Niara in forum Networking/Device Communication
    Replies: 9
    Last Post: 01-04-2007, 04:44 PM
  4. Where's the EPIPE signal?
    By marc.andrysco in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-23-2006, 08:04 PM
  5. Unicode vurses Non Unicode client server application with winsock2 query?
    By dp_76 in forum Networking/Device Communication
    Replies: 0
    Last Post: 05-16-2005, 07:26 AM