Is this right?

For all coding issues - MODers and programmers, HTML and more.

Moderators: Jeff250, fliptw

Post Reply
User avatar
Ferno
DBB Commie Anarchist Thug
DBB Commie Anarchist Thug
Posts: 15163
Joined: Fri Nov 20, 1998 3:01 am

Is this right?

Post by Ferno »

I'm trying to get this program to compile for a project I'm working on (2nd revision)

Code: Select all

//###########################################################
//my code
// Standard includes
#include <iostream.h>
#include "..\\socketobject\\SocketObject.h"

void vServerConnection( int iListenPort );
void vClientConnection( char *szServerIP, int iServerListenPort );

//
// ----> Main Program Function (REQUIRED or it may screw up)
//

int main( int argc, char *argv[] )
{
	if( argc < 3 ) {
		cout << "----------------------------------------------------" << endl;
		cout << "               ConnectionTest Help                  " << endl;
		cout << "----------------------------------------------------" << endl;
		cout << "Usage: ConnectionTest [Client/Server] [ip,port/port]" << endl;
		cout << "" << endl;
		cout << "Example: ConnectionTest client 198,168.0.1 6000" << endl;
		cout << "" endl;
		cout << "Example: ConnectionTest server 6000" << endl;
		cout << "" << endl;
		return ( 0 );
	}

	//---DCRAZY---
	// These two lines start up WinSock

	WSADATA wsaData;
	WSAStartup(MAKEWORD(2,2), &wsaData);

	//---END DCRAZY---

	//
	// 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 selected client; connect to given port and IP address
	//
	else {
		vClientConnection( argv[2], atoi( argv[3] ) );
	}
	WSACleanup();

	return( 1 );
}

// Function for server
void vServerConnection( int iListenPort )
{
	SocketObject	ServerSocketObject;
	SocketObject	ClientSocketObject;

	cout << "<Server> Attempting to listen on Port " << iListenPort << endl;

	// Attempt to start the Server on port 6000
	if ( ServerSocketObject.Bind( iListenPort ) )
	{
		cout << "<Server> Listening" << endl;

		// Listen for Connection on the Listen port,
		ServerSocketObject.Listen();

		// Accept the connection
		ServerSocketObject.Accept( ClientSocketObject );

		cout << "<Server> Client Connected to Port " << iListenPort << endl;

		// Disconnect the client
		ClientSocketObject.Disconnect();

		cout << "<Server> Client Disconnected" << endl;
	}
	else {
		cout << "<Server> Failed to Listen" << endl;
	}
}

//Function for Client
void vClientConnection( char *szServerIP, int iServerListenPort )
{
	SocketObject	ClientSocketObject;

	cout << "<Client> Connecting to " << szServerIP << ", Port " << iServerListenPort << endl;
	
	// Connect to thge IP and Port
	if( ClientSocketObject.Connect( szServerIP, iServerListenPort ) )
	{
		cout << "<Client> Connected" << endl;

		// Disconnect from the server
		ClientSocketObject.Disconnect();

		cout << "<Client> Disconnected from the server" << endl;
	}
	else {
		cout << "<Client> Failed to Connect" << endl;
	}
}
User avatar
DCrazy
DBB Alumni
DBB Alumni
Posts: 8826
Joined: Wed Mar 15, 2000 3:01 am
Location: Seattle

Post by DCrazy »

I don't see a Winsock init anywhere to justify your WSACleanup.

Damn, this BB makes reading code impossible.
User avatar
Ferno
DBB Commie Anarchist Thug
DBB Commie Anarchist Thug
Posts: 15163
Joined: Fri Nov 20, 1998 3:01 am

Post by Ferno »

ws2_32.lib has already been linked to the project.
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6459
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Post by fliptw »

whats the error, and which version of VC?
User avatar
Ferno
DBB Commie Anarchist Thug
DBB Commie Anarchist Thug
Posts: 15163
Joined: Fri Nov 20, 1998 3:01 am

Post by Ferno »

quite a few.. i'll post the revised code and the error log here after I try Borland.
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6459
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Post by fliptw »

do most of them involve endl in some manner?
User avatar
Ferno
DBB Commie Anarchist Thug
DBB Commie Anarchist Thug
Posts: 15163
Joined: Fri Nov 20, 1998 3:01 am

Post by Ferno »

here's the output log:

--------------------Configuration: ConnectionTest - Win32 Debug--------------------
Compiling...
ConnectionTest.cpp
D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(23) : error C2146: syntax error : missing ';' before identifier 'endl'
D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(23) : warning C4551: function call missing argument list
D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(34) : error C2059: syntax error : ')'
D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(58) : error C2296: '<<' : illegal, left operand has type 'char [19]'
D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(58) : error C2297: '<<' : illegal, right operand has type 'class ostream &(__cdecl *)(class ostream &)'
D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(66) : error C2001: newline in constant
D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(69) : error C2146: syntax error : missing ';' before identifier 'ClientSocketObject'
Error executing cl.exe.

ConnectionTest.exe - 6 error(s), 1 warning(s)
User avatar
Lothar
DBB Ghost Admin
DBB Ghost Admin
Posts: 12133
Joined: Thu Nov 05, 1998 12:01 pm
Location: I'm so glad to be home
Contact:

Re: Is this right?

Post by Lothar »

Code: Select all


	if ( ServerSocketObject.Bind( iListenPort ) )
	{
		cout < "<Server> Listening" << endl;
There should be two less-than's after the cout statement. It's trying to get the return value from the cout, and the string on the right, and see which is larger. I think this accounts for:

D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(23) : error C2146: syntax error : missing ';' before identifier 'endl'
D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(23) : warning C4551: function call missing argument list

Code: Select all

      cout << "<Server> Client Connected to Port : << iListenPort << endl;
You forgot to put an ending " in.

Clean these two up, and it should be easier to figure out what else is going on.
User avatar
Ferno
DBB Commie Anarchist Thug
DBB Commie Anarchist Thug
Posts: 15163
Joined: Fri Nov 20, 1998 3:01 am

Post by Ferno »

Lothar.. can you jump on AIM?

EDIT: revised error log:

D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(23) : error C2146: syntax error : missing ';' before identifier 'endl'
D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(23) : warning C4551: function call missing argument list
D:\JDS PROGRAMS\ConnectionTest\ConnectionTest.cpp(43) : error C2059: syntax error : ')'
User avatar
Lothar
DBB Ghost Admin
DBB Ghost Admin
Posts: 12133
Joined: Thu Nov 05, 1998 12:01 pm
Location: I'm so glad to be home
Contact:

Post by Lothar »

done...

OK, folks, move along now... nothing to see here... move along.
Post Reply