Baljeet
Member
- Jan 31, 2011
- 76
- 0
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
All Credits goes to one who really made this...
The code below is how it receives messages via a loop
Code:
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
All Credits goes to one who really made this...