Esempio n. 1
0
int main(int argc, char **argv){
	int port;
	string ipAddress;
	bool done = FALSE;
	char recMessage[STRLEN];
    char sendMessage[STRLEN];
	string input;
    
    port = atoi(argv[1]);
	//Client
	cout<<"Enter an IP address, 127.0.0.1 is the loopback address"<<endl;
	cin>>ipAddress;
	ClientSocket sockClient;
	cout<<"ATTEMPTING TO CONNECT..."<<endl;
	sockClient.ConnectToServer( ipAddress.c_str(), port );
	//Connected
	//sockClient.RecvData(recMessage, STRLEN);//Get ye here yon connection message
	//cout << recMessage<<endl;
	while ( !done ){     
		//sockClient.GetAndSendMessage(); //Sends input message
		input = sockClient.UserInput("test.txt");
		cout<<"\t--WAIT--"<<endl;
		sockClient.RecvData( recMessage, STRLEN );
		cout<<"Recv > "<<recMessage<<endl;
		/*
		if ( strcmp( recMessage, "end" ) == 0 || strcmp( sendMessage, "end" ) == 0 ){
			done = true;
		}
		*/
		
	}
	sockClient.CloseConnection();
}
Esempio n. 2
0
int main(){
	int port = 8888;
	string ipAddress;
	bool done;
	char recMessage[STRLEN];
    char sendMessage[STRLEN];

	//Client
	cout<<"Enter an IP address, 127.0.0.1 is the loopback address"<<endl;
	cin>>ipAddress;
	ClientSocket sockClient;
	cout<<"ATTEMPTING TO CONNECT..."<<endl;
	sockClient.ConnectToServer( ipAddress.c_str(), port );
	//Connected
	while ( !done ){     
		sockClient.GetAndSendMessage();
		cout<<"\t--WAIT--"<<endl;
		sockClient.RecvData( recMessage, STRLEN );
		cout<<"Recv > "<<recMessage<<endl;
		if ( strcmp( recMessage, "end" ) == 0 || strcmp( sendMessage, "end" ) == 0 ){
			done = true;
		}
	}
	sockClient.CloseConnection();
}
Esempio n. 3
0
int main()
{
        //Variables definitions:
        string ipAddress;
        int port = 54321;
        char recMessage[STRLEN];
        string userId;
        string command;

        cout << "Enter the Server's ip address: ";
        cin  >> ipAddress;

        ClientSocket sockClient;
        sockClient.ConnectToServer(ipAddress.c_str(), port);
        sockClient.RecvData( recMessage, STRLEN );

        if (checkName("LOGIN", recMessage)== false) {
                sockClient.CloseConnection();
        }else{
                cout << "Please enter the user-identifier: ";
                cin  >> userId;
                sockClient.SendData(stringToCharArray(userId));
                cin.clear();
                cin.ignore(1000, '\n'); //Removing the /n character for the next getline.
        }

        sockClient.RecvData( recMessage, STRLEN );

        if (checkName("WELCOME", recMessage)== false) {
                sockClient.CloseConnection();
                return 0;
        }else{

                while(true) {
                        cout << "Please enter the command: ";
                        getline(cin, command);
                        sockClient.SendData(stringToCharArray(command));
                        if (checkCommand(command, sockClient) == false) break;
                }

        }


        return 0;
}
Esempio n. 4
0
int main(int argc, char **argv){
	int port;
	string ipAddress = "127.0.0.1";
	//bool done = FALSE;
	char recMessage[STRLEN] = "\0";
	char sendMessage[STRLEN];
   	//Client
   	cout<<"Enter an IP address, 127.0.0.1 is the loopback address"<<endl;
   	//cin>>ipAddress;
   	ClientSocket sockClient;
	//port = atoi(argv[1]);
	cout << "AND AWAY WE GO!\n";
	
	sockClient.KnockKnock( ipAddress.c_str());
	
	sockClient.CloseConnection();
system("pause");
}
Esempio n. 5
0
void serverLoop() {
    int port = 666;
    //char *ipAddress = "127.0.0.1";
    string ipAddress;
    cout<<"1) Host server"<<endl;
    cout<<"2) Join server"<<endl;
    cout<<"3) Quit"<<endl;
    cin>>choice;
    if ( choice == 3 )
        exit(0);
    else if ( choice == 2 )
    {
        //Client
        cout<<"Enter an IP address, 127.0.0.1 is the loopback address"<<endl;
        cin>>ipAddress;
        cout<<"ATTEMPTING TO CONNECT..."<<endl;
        sockClient.ConnectToServer( ipAddress.c_str(), port );
        //Connected
		glutMainLoop();			// Enter GLUT main loop
        sockClient.CloseConnection();
    }
int main()
{
    int port = 8888;
    string ipAddress;
    char recMessage[STRLEN];

    //Client
    cout<<"Enter an IP address of server: ";
    cin>>ipAddress;

    ClientSocket sockClient;

    //connect to server
    cout<<"ATTEMPTING TO CONNECT..."<<endl << endl;
    sockClient.ConnectToServer( ipAddress.c_str(), port );

    //Recieve message from server (authentication request)
    sockClient.RecvData( recMessage, STRLEN );
    cout << recMessage;

    //send request to server (password)
    sockClient.GetAndSendMessage();

    //server response (valid or invalid password)
    sockClient.RecvData( recMessage, STRLEN );
    cout << recMessage << endl;

    string temp = recMessage;

    if (temp == "\t***INVALID CREDENTIALS****\nDISCONNECTING")
    {
        sockClient.CloseConnection();
        system("pause");
        return 0;
    }

    while (true)
    {
        //server list of actions to take
        sockClient.RecvData( recMessage, STRLEN );
        cout << recMessage;

        //client response of action
        sockClient.GetAndSendMessage();

        //server responds to selected action
        sockClient.RecvData( recMessage, STRLEN );

        //if quit is entered, server sends "Goodbye"
        string temp = recMessage;
        if (temp == "INVALID ENTRY")
        {
            cout << recMessage << endl;
        }
        else if (temp == "Goodbye")
        {
            sockClient.CloseConnection();
            cout << endl << "\t***DISCONNECTED" << endl;
            system("pause");
            return 0;
        }
        else if (temp == "List")
        {
            sockClient.RecvData( recMessage, STRLEN );
            temp = recMessage;
            if (temp != "***No files in directory"){
                int num = atoi(recMessage);
                for (int i = 0; i < num; i++)
                {
                    sockClient.RecvData( recMessage, STRLEN );
                    cout << endl <<"\t" << recMessage;
                }
                cout << endl << endl;
            }
        }

        else if(temp == "send")
        {
            cout << "Enter file name: ";
            string fileName;
            cin >> fileName;

            char *cfilename = new char[fileName.length()+1];
            strcpy(cfilename,fileName.c_str());
            sockClient.SendData(cfilename);

            sockClient.RecvData(recMessage, STRLEN);
            temp = recMessage;
            if(temp == "fail"){
                cerr << "\tFile does not exist" << endl;
            }
            else if(temp == "okay"){
                ofstream fout;
                fout.open(fileName.c_str());
                sockClient.RecvData(recMessage, STRLEN);
                //cout << "..." << recMessage << endl;
                string txt(recMessage);
                while(txt != "EOFEOFEOFEOFEOFEOF"){
                    fout << txt << endl;
                    sockClient.RecvData(recMessage, STRLEN);
                    txt = recMessage;
                }
                fout.close();
            }
        }
    }