Click to See Complete Forum and Search --> : how to access a function inside a public class declared under namespace VCNET


nashs
July 30th, 2004, 05:57 AM
hi all im a moderate programmer tryin to create a asynchronous server client commn. with tcp ip protocol..
the program given below is the included in a header file connects.h.
i am able to connect to the client and wanted to send data...I tried to access the senddata function declared in the Connection class....But i get an error function...

i trid to declare as VCNET::Connection::SendData("YYYYY");

also as Connection a;
a.SendData("YYYY");
in the main program.....

Can any one help me on this plz....

The error message recieved is as below:

C2352: 'VCNET::Connection::SendData::VCNET::Connection::SendData': inadmissible proclamation of a not static Memberfunktion

namespace VCNET
{
//////// The class encapsulates the functionality of a client connection

public __gc class Connection
{
static Int32 READ_BUFFER_SIZE = 255;

public:
Connection(TcpClient* client)
{
this->client = client;
readBuffer = new Byte[READ_BUFFER_SIZE];

//This starts the asynchronous read thread. The data will be saved in the read buffer.

AsyncCallback* CB = new AsyncCallback(this, StreamReceiver);
this->client->GetStream()->BeginRead(readBuffer, 0, READ_BUFFER_SIZE, CB, 0);
}

private:
TcpClient* client;
Byte readBuffer[];
String* strName;


public:
//The Name property uniquely identifies the user connection

__property String* get_Name(void) {return strName;}
__property void set_Name(String* Value) { strName = Value;}

__event void LineReceived(Connection* sender, String* Data);


// This function uses a StreamWriter to send a message to the user
System::Void SendData(String* Data)
{
// Monitor ensures that no other thread try to use the stream at the same time
Monitor::Enter(client->GetStream());
IO::StreamWriter* writer = new IO::StreamWriter(client->GetStream());
writer->Write(String::Concat(Data,S"\r\n"));

//Make sure all the data is sent now
writer->Flush();

Monitor::Exit(client->GetStream());
}

//This is the callback function for TcpClient->GetStream()->Begin. It begins an asynchronous read
//from a stream.

void StreamReceiver(IAsyncResult* ar)
{
Int32 BytesRead;
String* strMessage;

try
{
// Ensure that no other threads try to use the stream at the same time
Monitor::Enter(client->GetStream());

//Finish asynchronous read into readBuffer and get number of bytes read.
BytesRead = client->GetStream()->EndRead(ar);

Monitor::Exit(client->GetStream());


//Convert the byte array the message was into, minus one for the carriage return.
strMessage = Encoding::ASCII->GetString(readBuffer, 0, BytesRead-1);
LineReceived(this, strMessage);

//Ensure that no other threads try to use the stream at the same time.
Monitor::Enter(client->GetStream());

//Start a new asynchronous read into readBuffer.
AsyncCallback* CB = new AsyncCallback(this, StreamReceiver);
client->GetStream()->BeginRead(readBuffer, 0, READ_BUFFER_SIZE, CB, 0);

Monitor::Exit(client->GetStream());
}
catch(Exception*)
{
}
}
};
}