Jump to content

Code: Managed C++ .NET 2.0: Instant Messanger Server

- - - - -

  • Please log in to reply
No replies to this topic

#1
Lop

Lop

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,172 posts
This is the code for a Visual Studio Managed C++ .net Instant Messanger Server. I say server because it was meant to receive the messages.

The code below is how it receives messages via a loop


	private: void RunIMServer() {

				 while (!stopped) {

					 TcpClient^ client = imListener->AcceptTcpClient();

					 String^ data;

					 

					 // See if the client is connected

					 while (client->Connected) {

					 //if (client->Connected) {

						 NetworkStream^ stream = client->GetStream();


						 // Create our byte array for reading

						 array<unsigned char,1>^ bytes = gcnew array<unsigned char>(256);


						 // Loop to receive all the data sent by the client.

						while (int i = stream->Read(bytes, 0, bytes->Length)) {   

							// Translate data bytes to a ASCII String*

							data = System::Text::Encoding::ASCII->GetString(bytes, 0, i);

							insertText(data);

						}


						// Close our connect

						//client->Close();

						

					 }

					 // Close our connect

					 client->Close();


				 } // End While


			 } // End RunIMServer







1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users