ppuniversal
February 22nd, 2007, 07:23 AM
hello,
my program snippet:
/*****************************/
/******runThread Function*****/
/*to accept other client connections*/
/*****************************/
DWORD WINAPI runThread(LPVOID param)
{
SOCKET acceptSocket; //Socket variable
HANDLE hThreadC; //Handle to thread
DWORD ThreadIdC; //used to store the thread id
//Parent object (not used anywhere)
GridServerCThread *ob = (GridServerCThread *)param;
printf( "\n A New Thread for Accepting client connections created.\n");
// Create a socket.
SOCKET clientSocket;
clientSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( clientSocket == INVALID_SOCKET )
{
printf( "\n Error at socket(): %ld\n", WSAGetLastError() );
WSACleanup();
return 0;
}
// Bind the socket.
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
clientService.sin_port = htons( 4000 );
if ( bind( clientSocket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR )
{
printf( "\n bind() failed.\n" );
closesocket(clientSocket);
return 0;
}
else
{
// Listen on the socket.
if ( listen( clientSocket, 1 ) == SOCKET_ERROR )
printf( "\n Error listening on socket.\n");
else
{
printf( "\n Listening for Client connection......\n" );
// Accept connections.
while (true)
{
acceptSocket = accept( clientSocket, NULL, NULL );
if(acceptSocket)
{
GridServerCThread client_conn_object;
client_conn_object.c_socket = acceptSocket;
hThreadC = CreateThread(NULL,
0,
runThreadC,
(LPVOID)&client_conn_object,
0,
&ThreadIdC);
client_conn_object.hThreadC = hThreadC;
client_conn_object.ThreadIdC = ThreadIdC;
}
else
return 0;
}
}
}
return 0;
}
//Constructor, coming from main() to create a
//thread to accept connections from CLIENTS
//for all the actual work.
GridServerCThread :: GridServerCThread()
{
HANDLE hThread; //Handle to thread
DWORD ThreadId; //used to store the thread id
hThread = CreateThread( NULL,
0,
runThread,
(LPVOID)this,
0,
&ThreadId);
this->hThreadC = hThreadC;
this->ThreadIdC = ThreadIdC;
}
On compiling the program, I get the error :
------ Build started: Project: GridServer, Configuration: Debug Win32 ------
Linking...
GridServerSThread.obj : error LNK2005: "unsigned long __stdcall runThread(void *)" (?runThread@@YGKPAX@Z) already defined in GridServerCThread.obj
E:\SmartSafe\Debug\GridServer.exe : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at "file://e:\SmartSafe\GridServer\Debug\BuildLog.htm"
GridServer - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
what should I do??
where is the error, even when I searched MSDN, it told that to get rid of LNK2005 use /FORCE in linker option. I did that, but then my program does not run properly.
Please reply
Pawan
my program snippet:
/*****************************/
/******runThread Function*****/
/*to accept other client connections*/
/*****************************/
DWORD WINAPI runThread(LPVOID param)
{
SOCKET acceptSocket; //Socket variable
HANDLE hThreadC; //Handle to thread
DWORD ThreadIdC; //used to store the thread id
//Parent object (not used anywhere)
GridServerCThread *ob = (GridServerCThread *)param;
printf( "\n A New Thread for Accepting client connections created.\n");
// Create a socket.
SOCKET clientSocket;
clientSocket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );
if ( clientSocket == INVALID_SOCKET )
{
printf( "\n Error at socket(): %ld\n", WSAGetLastError() );
WSACleanup();
return 0;
}
// Bind the socket.
sockaddr_in clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
clientService.sin_port = htons( 4000 );
if ( bind( clientSocket, (SOCKADDR*) &clientService, sizeof(clientService) ) == SOCKET_ERROR )
{
printf( "\n bind() failed.\n" );
closesocket(clientSocket);
return 0;
}
else
{
// Listen on the socket.
if ( listen( clientSocket, 1 ) == SOCKET_ERROR )
printf( "\n Error listening on socket.\n");
else
{
printf( "\n Listening for Client connection......\n" );
// Accept connections.
while (true)
{
acceptSocket = accept( clientSocket, NULL, NULL );
if(acceptSocket)
{
GridServerCThread client_conn_object;
client_conn_object.c_socket = acceptSocket;
hThreadC = CreateThread(NULL,
0,
runThreadC,
(LPVOID)&client_conn_object,
0,
&ThreadIdC);
client_conn_object.hThreadC = hThreadC;
client_conn_object.ThreadIdC = ThreadIdC;
}
else
return 0;
}
}
}
return 0;
}
//Constructor, coming from main() to create a
//thread to accept connections from CLIENTS
//for all the actual work.
GridServerCThread :: GridServerCThread()
{
HANDLE hThread; //Handle to thread
DWORD ThreadId; //used to store the thread id
hThread = CreateThread( NULL,
0,
runThread,
(LPVOID)this,
0,
&ThreadId);
this->hThreadC = hThreadC;
this->ThreadIdC = ThreadIdC;
}
On compiling the program, I get the error :
------ Build started: Project: GridServer, Configuration: Debug Win32 ------
Linking...
GridServerSThread.obj : error LNK2005: "unsigned long __stdcall runThread(void *)" (?runThread@@YGKPAX@Z) already defined in GridServerCThread.obj
E:\SmartSafe\Debug\GridServer.exe : fatal error LNK1169: one or more multiply defined symbols found
Build log was saved at "file://e:\SmartSafe\GridServer\Debug\BuildLog.htm"
GridServer - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
what should I do??
where is the error, even when I searched MSDN, it told that to get rid of LNK2005 use /FORCE in linker option. I did that, but then my program does not run properly.
Please reply
Pawan