Archived

This topic is now archived and is closed to further replies.

char prob in BCB

This topic is 5746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sup guys Im trying to write this server/client program that sets the server to listen on the specified port and the client to connect to thespecified ip address and port of the server. Here is the code for this particular part of the program: //Standards Includes #include <iostream.h> #include "C:\Program Files\MultiplayerGP\Chapter4\SendDataTest\SocketObject.h" void vServerConnection( int iListenPort ); void vClientConnection( char *szServerIP, int iServerListenPort ); //----> Main prog function int main( int argc, char *argv[] ) {if( argc < 3 ) { cout << "---------------------------------" << endl; cout << " SendDataTest Help " << endl; cout << "---------------------------------" << endl; cout << "Usage: SendDataTest [client\server] [ip.port/port.port]" << endl; cout << "" << endl; cout << "Example: SendDataTest client 198.168.0.1 6000 " << endl; cout << "" << endl; cout << "Example: SendDataTest server 6000" << endl; cout << "" << endl; return( 0 ); } //if user selected server listen on the given port and assign connection to the second port number if( !stricmp( argv[1], "server" )) { vServerConnection( atoi( argv[2])); } //User selecteds Client; connect to given port and ip address else { vClientConnection( argv[2], atoi( argv[3] )); } return( 1 ); } // function server void vServerConnection( int iListenPort ) { SocketObject ServerSocketObject; SocketObject ClientSocketObject; char DataPacket[128]; int iBytesReceived = 0; cout << " Attempting to listen to port" << iListenPort << endl; //Attempt to start server if ( ServerSocketObject.Bind( iListenPort ) ) { cout << " Listening" << endl; // Listen for connection on the listen port ServerSocketObject.Listen( ); //Accept the connection ServerSocketObject.Accept( ClientSocketObject ); cout << " Client Connected to Port" << iListenPort << endl; // Received Data iBytesReceived = ClientSocketObject.Recv(&DataPacket, 128, 0); cout << " Received " << iBytesReceived << " Bytes" < endl; cout << " Data Received = " << DataPacket << endl; //Disconnect the client ClientSocketObject.Disconnect(); cout << " Client Disasconnected " << endl; } else { cout << " Failed to listen" << endl; } } //Function For the client void vClientConnection( char *szServerIP, int iServerListenPort ) { SocketObject ClientSocketObject; char DataPacket[128]; int iByresSent = 0; cout << " Connecting to " << szServerIP << ", Port" << iServerListenPort << endl; //conect to the IP and Port if( ClientSocketObject.Connect( szServerIP, iServerListenPortt )) { cout << " Connected " << endl; //populate the data packet strcpy(DataPacket, "TestData from client"); //send data iBytesSent = ClientSocketObject.Send(DataPacket, 128, 0); cout << " Transmitted" << iBytesSent << " Bytes" << endl; //Disconnect from the server ClientSocketObject.Disconnect(); cout << " Disconnected From Server" << endl; } else { cout << " Failed to connect" << endl; } } i get this error when building: [C++ Error] SendDataTest1.cpp(57): E2034 Cannot convert ''char ( *)[128]'' to ''char *'' for this line of code: // Received Data iBytesReceived = ClientSocketObject.Recv(&DataPacket, 128, 0); I realy dont know what to ask but i have a hunch that there is somthing to do with a header that need to be altered ??? Sakira Master Newbie

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
looks like you may have a data type error try changing char DataPacket[128] to char *DataPacket[128] making it an array of pointers . Or you could also try changing your functions parameters to agree with your original declarations.

al_the_golfer

Share this post


Link to post
Share on other sites
I removed the & and I got this error:
[C++ Error] SendDataTest1.cpp(58): E2335 Overloaded 'endl' ambiguous in this context


I cant find anything
HELLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
mEEEEEEEEEEEEEEEEEEEEEE

lol
no really
i cant find anything

Sakira

[edited by - sakira on March 20, 2002 2:21:03 PM]

Share this post


Link to post
Share on other sites