Hello, I need some help.. I am using BCB6 and made a program. Now I want two computers that are running the same program to be able to exchange data.
example
Computer A
Computer B
Computer A will connect to Computer B
and how can they know "ok were both ready lets exchange data"
[CODE]
Computer A gives ready signal
Computer B gives ready signal
When both are ready Computer A will connect to computer B[/CODE]
Computer A will get Computer B's values
[CODE]
CompAWeight = weight (computer b's)
CompACost = Cost (computer b's)
[/CODE]
Now computer A will tell computer b his values
[CODE]
CompBWeight = weight (computers A's)
CompBCost = Cost (computers A's)[/CODE]
Now Computer A will leave computer B.
[CODE]
Close Connection
[/CODE]
Right now any suggestion would be GREAT!!!
Cause I have no IDEAL how to do this
or were to start. I have the program done that calculates the data, Now i just need to exchange it.
I am using client and server sockets but can easily adopt something else that would make the easier.
Thanks a million
Squills
Comments
This is for event when ready Checkbox is clicked:
[code] if(CheckBox1->Checked)
{
// Conn is the TNMUDP component
Conn->RemoteHost = Edit1->Text;
Conn->RemotePort = atoi(Edit2->Text.c_str());
Conn->LocalPort = atoi(Edit3->Text.c_str());
AnsiString readymsg = "I'm ready";
Conn->SendBuffer(readymsg.c_str(),readymsg.Length(),readymsg.Length());
// otherisready is bool value that changes according to what other computer sends
if(otherisready == true)
{
// Memo1 is the message computer sends
Conn->SendBuffer(Memo1->Text.c_str(),Memo1->Text.Length(),Memo1->Text.Length());
}
}
else
{
Conn->RemoteHost = Edit1->Text;
AnsiString readymsg = "I'm NOT ready";
Conn->SendBuffer(readymsg.c_str(),readymsg.Length(),readymsg.Length());
}[/code]
And this is for OnDataReceived event:
[code] if(FromIP == Edit1->Text)
{
AnsiString recmsg;
recmsg.SetLength(NumberBytes);
Conn->ReadBuffer(recmsg.c_str(),NumberBytes,NumberBytes);
if(recmsg == "I'm ready")
{
otherisready = true;
if(CheckBox1->Checked)
Conn->SendBuffer(Memo1->Text.c_str(),Memo1->Text.Length(),Memo1->Text.Length());
}
else if(recmsg == "I'm NOT ready")
{
otherisready = false;
}
else
{
// Memo2 is field where received message is written
if(CheckBox1->Checked)
Memo2->Text = recmsg;
}
}[/code]
I hope the code is clear enough.
second Do i need to add a header for
recmsg.SetLength(NumberBytes);
NumberBytes;
or is that declared somewere else in your code?
thanks
Squills
I sort of am used to it
[b]NumberBytes[/b] is a variable that is given in the event:
[code]void __fastcall TForm1::ConnDataReceived(TComponent *Sender,
int NumberBytes, AnsiString FromIP, int Port)
{
...[/code]
So no, you don't need to declare it anywhere yourself.