Article View: borland.public.cppbuilder.internet.socket
Article #3014TWinSocketStream and threading
From: Maurice Anderson
Date: Mon, 19 Dec 2005 22:50
Date: Mon, 19 Dec 2005 22:50
42 lines
2396 bytes
2396 bytes
I am able to send data to a test server across the network using the code
below from the help file. My Question is, (1) how can I modify the server
code below to use pStream->ReadBuffer(Buffer, x) instead of
pStream->Read(Buffer, 10). (2) If I want to send binary data such as a file,
can I still use Read or must I use ReadBuffer? (3) How can I modify it to
send data to a client? (4) Once the data is read on the server, how can I
send it over to the main thread for processing(I know I should use
sycnhronize some way, but how)? Is that even wise? (5) Is it wise or
necesarry to use a seperate thread on the client side to send and receive
data as well?
while (!Terminated && ClientSocket->Connected)
{
try
{
pStream = new TWinSocketStream(ClientSocket, 60000);
try
{
memset(Buffer, 0, 10); // initialize the buffer
// give the client 60 seconds to start writing
if (pStream->WaitForData(60000))
{
test = sizeof(pStream);
if (pStream->Read(Buffer, 10) == 0)
ClientSocket->Close(); // close the connection
// now process the request ...
Form1->Memo1->Lines->Add((char *)Buffer);
}
else
ClientSocket->Close(); // if client doesn't start, close
}
__finally
{
delete pStream;
}
}
catch (Exception &E)
{
HandleException();
}
}
Technical Details
Message-ID:
<43a738ea$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 11508e,75fde898af9e336,start X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Maurice Anderson" <mauriceanderson@hotmail.com> Newsgroups: borland.public.cppbuilder.internet.socket Subject: TWinSocketStream and threading Date: Mon, 19 Dec 2005 14:50:02 -0800 Lines: 44 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 64.30.203.223 Message-ID: <43a738ea$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1135032554 64.30.203.223 (19 Dec 2005 14:49:14 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail