Click here to Skip to main content
15,912,756 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
QuestionSocket listening but not accepting, why? Pin
randomVariable26-Jan-09 20:46
randomVariable26-Jan-09 20:46 
QuestionRe: Socket listening but not accepting, why? Pin
led mike27-Jan-09 4:49
led mike27-Jan-09 4:49 
AnswerRe: Socket listening but not accepting, why? Pin
randomVariable27-Jan-09 6:07
randomVariable27-Jan-09 6:07 
GeneralRe: Socket listening but not accepting, why? Pin
staticv28-Jan-09 2:09
staticv28-Jan-09 2:09 
QuestionDoes anyone know how to use Mschart in Visual c++? Pin
sai5623-Jan-09 22:21
sai5623-Jan-09 22:21 
AnswerRe: Does anyone know how to use Mschart in Visual c++? Pin
N a v a n e e t h23-Jan-09 23:10
N a v a n e e t h23-Jan-09 23:10 
QuestionLinker Error in CLR library file while linking to native C++ application. Pin
Member 570390523-Jan-09 12:42
Member 570390523-Jan-09 12:42 
Questionthread creation Pin
staticv23-Jan-09 5:43
staticv23-Jan-09 5:43 
I'm getting a few errors while creating a new thread, I don't know what am I doing wrong but somethings not working properly in the Thread creation in the above code.

// ThreadedServer.cpp : main project file.

#include "stdafx.h"

using namespace System;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::IO;
using namespace System::Threading;
using namespace System::Collections;
using namespace System::Text;

ref class ClientHandler
{
public:
	TcpClient^ clientSocket;

	void RunClient()
	{
		// Create the stream classes
		StreamReader^ readerStream = gcnew StreamReader(clientSocket->GetStream());
		NetworkStream^ writerStream = clientSocket->GetStream();

		String^ returnData = readerStream->ReadLine();
		String^ userName = returnData;

		Console::WriteLine("Welcome " + userName + " to the Server");

		while (true)
		{
			returnData = readerStream->ReadLine();

			if (returnData->IndexOf("QUIT") > -1)
			{
				Console::WriteLine("Bye Bye " + userName);
				break;
			}

			Console::WriteLine(userName + ": " + returnData);
			returnData += "\r\n";

			array<byte>^ dataWrite = Encoding::ASCII->GetBytes(returnData);
			writerStream->Write(dataWrite, 0, dataWrite->Length);
		}

		clientSocket->Close();
	}
};

const int ECHO_PORT = 8080;

void main(void)
{
	try
	{
		// Bind the server to the local port
		TcpListener^ clientListener = gcnew TcpListener(ECHO_PORT);

		// Start to listen
		clientListener->Start();

		Console::WriteLine("Waiting for connections...");

		while (true)
		{
			// Accept the connection
			TcpClient^ client = clientListener->AcceptTcpClient();

			ClientHandler^ cHandler = gcnew ClientHandler();

			cHandler->clientSocket = client;

			// Create a new thread for the client
			// is anything wrong here?  
			Thread^ clientThread = gcnew Thread(gcnew ThreadStart(cHandler, &cHandler::RunClient));
			clientThread->Start();
		}

		clientListener->Stop();
	}
	catch (Exception^ e)
	{
		Console::WriteLine("Exception: " + e);
	}
}</byte>


Here are the errors I'm getting

1>.\ThreadedServer.cpp(57) : warning C4947: 'System::Net::Sockets::TcpListener::TcpListener' : marked as obsolete
1>        Message: 'This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead.
1>.\ThreadedServer.cpp(74) : error C2825: 'cHandler': must be a class or namespace when followed by '::'
1>.\ThreadedServer.cpp(74) : error C2039: 'RunClient' : is not a member of '`global namespace''
1>.\ThreadedServer.cpp(74) : error C2146: syntax error : missing ')' before identifier 'RunClient'
1>.\ThreadedServer.cpp(74) : error C3924: error in argument #2 of delegate 
constructor call 'System::Threading::ThreadStart':
1>        pointer to member function expected
1>.\ThreadedServer.cpp(74) : error C2146: syntax error : missing ')' before identifier 'RunClient'
1>.\ThreadedServer.cpp(74) : error C2146: syntax error : missing ';' before identifier 'RunClient'
1>.\ThreadedServer.cpp(74) : error C2059: syntax error : ')'
1>.\ThreadedServer.cpp(74) : error C2059: syntax error : ')'
1>.\ThreadedServer.cpp(74) : error C2065: 'RunClient' : undeclared identifier


Any hints will be really appreciated Smile | :)

Top Web Hosting Providers[^]

Do, or do not. There is no 'try'.

AnswerRe: thread creation Pin
teejayem23-Jan-09 7:46
teejayem23-Jan-09 7:46 
GeneralRe: thread creation Pin
staticv23-Jan-09 8:43
staticv23-Jan-09 8:43 
Questionhow to determine application path Pin
naveen_bij22-Jan-09 23:57
naveen_bij22-Jan-09 23:57 
AnswerRe: how to determine application path Pin
Giorgi Dalakishvili23-Jan-09 1:08
mentorGiorgi Dalakishvili23-Jan-09 1:08 
GeneralRe: how to determine application path Pin
naveen_bij27-Jan-09 1:09
naveen_bij27-Jan-09 1:09 
Questionsend serialized object Pin
staticv22-Jan-09 5:15
staticv22-Jan-09 5:15 
AnswerRe: send serialized object Pin
led mike22-Jan-09 6:19
led mike22-Jan-09 6:19 
GeneralRe: send serialized object [modified] Pin
staticv22-Jan-09 7:59
staticv22-Jan-09 7:59 
GeneralRe: send serialized object Pin
led mike22-Jan-09 8:22
led mike22-Jan-09 8:22 
GeneralRe: send serialized object [modified] Pin
staticv23-Jan-09 0:24
staticv23-Jan-09 0:24 
GeneralRe: send serialized object Pin
led mike23-Jan-09 5:10
led mike23-Jan-09 5:10 
GeneralRe: send serialized object Pin
staticv23-Jan-09 5:13
staticv23-Jan-09 5:13 
QuestionProblem with File Open Dialog Pin
bubuzzz22-Jan-09 5:05
bubuzzz22-Jan-09 5:05 
AnswerRe: Problem with File Open Dialog Pin
AVTProgrammerKeith12-Feb-10 6:12
AVTProgrammerKeith12-Feb-10 6:12 
QuestionT-SQL using Sql server Pin
maheesh22-Jan-09 2:29
maheesh22-Jan-09 2:29 
AnswerRe: T-SQL using Sql server Pin
led mike22-Jan-09 4:35
led mike22-Jan-09 4:35 
QuestionAbout T-SQL Pin
maheesh22-Jan-09 2:28
maheesh22-Jan-09 2:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.