Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UDP connection

Status
Not open for further replies.

viper123

Technical User
Jun 21, 2003
14
0
0
RO
Hey guys, I wonder if you could help me in a situation, I would be gratefull to you if you could.
I want to build a chat program using the UDP broadcasting or the IP multicasting but I couldn't find any reference for this issue. What components should I use for this job? I tried TServerSocket and TClient Socket and all managed to do was a server-client application, which is quite innapropiate for what I wanna do.

Another issue I'm dealing with is how to send/receive a stream via a Client or a Server Socket.

So, if you have any suggestion please let me know, I would be gratefull.
 
Based on what kind of information you want to send, you could use the following methods of the TServerSocket and TClientSocket:

int SendText(AnsiString Text);
int SendBuf(void *Buf, int Count);
bool SendStream(Classes::TStream* AStream);

AnsiString ReceiveText(void);
int ReceiveBuf(void *Buf, int Count);

To use these,
MyServerSocket->Socket->SendText("Hello World");

void __fastcall TForm1::MyClientSocketRead(TObject *Sender,
TCustomWinSocket *Socket)
{
GlobalAnsiString = MyClientSocket->Socket->ReadText();
}

Now, the question becomes "Do you want it to be secure communication?" If so, the easiest way without changing the scheme implemented above is write a simple algorithm to encode the text. You are limited to simple encryption that way. To use serious encryption, change the above to write from a buffer, one that's been encrypted with a good algorithm. Then read a buffer back in and decode it.

Chris
 
Thanks a lot for your tip, but I still have some vaguness. For example, if I want to send/read a text I use SendText/Receive text, if I want to send/read a buffer, I use SendBuf/ReceiveBuf methods according to you. But if I want to receive a stream how should I do this? I use SendStream method to send it, but what method do I use to receive it from the socket, 'cause I don't have a ReceiveStream method to do this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top