char prob in BCB

Started by
3 comments, last by SAKIRA 22 years, 1 month ago
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
Advertisement
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
Hello

I tried turning char datapaket into a pointer and got the same error.


???
Sakira
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]
nm
thx you guys
i fixed it

This topic is closed to new replies.

Advertisement