Article View: borland.public.cppbuilder.internet.socket
Article #5281Re: TServerSocket v/s Indy
From: Hans Galema
Date: Fri, 17 Sep 2004 07:48
Date: Fri, 17 Sep 2004 07:48
50 lines
3010 bytes
3010 bytes
JD wrote: > I have. The server hides in the system tray and the client > connects but that's all that I have. Can you send and receive ? As that is what the chat example does. That example uses SendText() which is not a good idea. Better use SendBuf() end send the size of the message first. How you can do that has been posted here many times. Lets assume you have a char buffer that contains the message to be send. char buffer [ ]; int size = ...; // amount of bytes in the buffer. Socket->SendBuf ( &size, sizeof(size) ); Socket->SendBuf ( buffer, size ); Thats' all, but not really. You have to check the return value of SendBuf() as it will not always send the requested amount. If it did not you should use SendBuf() later again with the remaining bytes. A loop with a Sleep() in it usually does the job. I posted complete code to send before in this group so you should be able to find it. Als Remy posted samples. If you need help with a sample than please start a new thead for a specific problem. > I could use a sample that sends and receives to and from the > server and something that shows me how to iterate the > connected client on the server side. Iterate the ServerSocket1->Socket->Connection[] array. That array contains the client sockets. Once you gabbed the Socket you can than send to that client. The way the server sends with SendBuf is the same as clients do. So you could make a function that takes a Socket, the buffer and the size as parameter and handles the complete send. >>But what do you want ? Blocking ? Non-blocking ? > > You know better than me. What do you think? Oh no. You have to decide. You could try both. Note that you can make a non-blocking server and blocking clients. Al combinations are possible. Hans.
Technical Details
Message-ID:
<414a9620$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!news.tele.dk!news.tele.dk!small.news.tele.dk!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<41415d94$1@newsgroups.borland.com> <4141743f$1@newsgroups.borland.com> <4149ac08$1@newsgroups.borland.com> <4149b0c8$1@newsgroups.borland.com> <4149bee8$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,a7601bf51960fa65 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Fri, 17 Sep 2004 09:48:42 +0200 From: Hans Galema <dontusethis@dontusethis.nl> User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: TServerSocket v/s Indy References: <41415d94$1@newsgroups.borland.com> <4141743f$1@newsgroups.borland.com> <4149ac08$1@newsgroups.borland.com> <4149b0c8$1@newsgroups.borland.com> <4149bee8$1@newsgroups.borland.com> In-Reply-To: <4149bee8$1@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 129.125.201.248 Message-ID: <414a9620$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1095407136 129.125.201.248 (17 Sep 2004 00:45:36 -0700) Lines: 50 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!news.tele.dk!news.tele.dk!small.news.tele.dk!npeer.de.kpn-eurorings.net!feed.news.schlund.de!schlund.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail