Thread: passing function problem

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    84

    passing function problem

    ok i build the client and i get the following errors

    C:\Documents and Settings\chris285\Desktop\tutorials\Sending and Receiving\Client\main.cpp(17) : error C2660: 'connecttoserver' : function does not take 0 parameters
    C:\Documents and Settings\chris285\Desktop\tutorials\Sending and Receiving\Client\main.cpp(21) : error C2660: 'disconnectfromserver' : function does not take 0 parameters
    Error executing cl.exe.

    on these lines of code in the main.cpp file

    Code:
    #include "connecting.h"
    #include <iostream>
    #include "mesagesend.h"
    
    #include <winsock2.h>
    
    #include <stdio.h>
    
    using namespace std;
    
    int main()
    {
    	connecting client;
    
    	mesagesend chat;
    
    	client.connecttoserver();
    
    	chat.sendmessage();
    
    	client.disconnectfromserver();
    	return 0;
    }
    how would this be done?

    would it be stated in the function? e.g. port == kinda thing?

    trouble is the ip address of the pc is going to be differnt on each pc as it will be used on my uni network, so really i need a way for the program to find the computers ip address and what not

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    84
    ok solved 1 problem, in the main i changed the line to

    Code:
    client.disconnectfromserver(chat.mysocket);
    still got the error on the connecttoserverfunction though

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    Uh, stab in the dark, but maybe the connecttoserver function doesn't take zero parameters?

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by chris285
    Code:
    client.connecttoserver();
    Code:
    int connecttoserver(unsigned short port, const char *serverName)
    You have all the code right in front of you. How about not double-posting?
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    84
    Code:
    int connecting::connecttoserver(unsigned short port, const char *servername)
    {
    	int error;
    
    	WSAData wsaData;	// the winsock data structure
    
    	
    	if ((error = WSAStartup(MAKEWORD(2, 2), &wsaData)) == SOCKET_ERROR) {
    		cout << "Winsock Start Up Failed!" << endl;							// startup winsock
    		return -1;
    	}
    
    	
    	int mySocket = socket(AF_INET, SOCK_STREAM, 0);		// create my socket
    
    	
    	if (mySocket == SOCKET_ERROR) {
    		cout << "Error Opening Socket!" << endl;			// make sure nothing bad happened
    		return -1;
    	}
    
    	struct hostent *host_entry;
    
    
    	if ((host_entry = gethostbyname(servername)) == NULL) {				// setup the host entry
    		cout << "Could not find host!" << endl;
    	}
    
    	struct sockaddr_in server;
    
    	
    	server.sin_family = AF_INET;
    	server.sin_port = htons(port);									// fill in the server socket info
    	server.sin_addr.s_addr = *(unsigned long*) host_entry->h_addr;
    
    	
    	if (connect(mySocket, (sockaddr*)&server, sizeof(server)) == SOCKET_ERROR) {		// connect to the server
    		cout<< "Error connecting to server!" << endl;
    	}
    
    	cout << "Connection Established" << endl;
    
    	return mySocket;
    }
    thats the function, i just can't see where i am going wrong. prob been staring at the code too long

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Go and read up on functions, argument to functions and functions in classes!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM