Thread View: borland.public.cppbuilder.internet.socket
3 messages
3 total messages
Started by Vladimir Stefanovic
Fri, 13 Aug 2004 19:52
{ctNonBlocking, ctBlocking} and {stNonBlocking, stThreadBlocking}
Author: Vladimir Stefanovic
Date: Fri, 13 Aug 2004 19:52
Date: Fri, 13 Aug 2004 19:52
55 lines
2602 bytes
2602 bytes
Hi, I have some basic questions about propper usage of... ClientType: ctNonBlocking & ctBlocking ServerType: stNonBlocking & stThreadBlocking ...for TServerSocket and TClientSocket, and some other related questions. 1) Is TMemoryStream appropriate container for the date that has to be sent on client side and received on the server side? If not, what is the adequate one? 2) If I want to send 100 KB of data from a client to server, and that't the only connection (only one client to connect to the server) what should I use for a ClientType and what for a ServerType. a) What technique of sending should I use for this? b) What mechanism for catching messages should I use for that? Is TClientSocket::OnError() & TServerSocket::OnClientError() enough (for writing in a log for example)? c) When some error occur while process of sending data, is some kind of immediate retry of the whole process of any sense? d) How can I know that the data has been sent successfuly in this case? 3) When sending up to 100 bytes of ASCII string from only one client to server, should I use SendText() insted of SendBuf()? a) Why SendBuf() is usualy recomended one? b) Should I use the same ClientType and ServerType like in point 2 ? 4) If I have two (or more) clients that in some moment (mabe the same) wants to send the data (max 20 KB) to the client what ClientType and ServerType should I then use? a) What technique of sending should I use? (I think maybe of TWinSocketStream). b) How can I know that the data has been sent successfuly in this case? Any code, pseudo, link, and similar would be of great help. Best regards, Vladimir Stefanovic
Re: {ctNonBlocking, ctBlocking} and {stNonBlocking, stThreadBlocking}
Author: Remy Lebeau (TeamB)
Date: Fri, 13 Aug 2004 20:11
Date: Fri, 13 Aug 2004 20:11
90 lines
4512 bytes
4512 bytes
"Vladimir Stefanovic" <spam@not.needed> wrote in message news:411d1c29@newsgroups.borland.com... > 1) Is TMemoryStream appropriate container for the date > that has to be sent on client side and received on the > server side? If not, what is the adequate one? That depends on what you are actually trying to do. TMemoryStream is certainly not a requirement, but it can be helpful at times. That is a general code design issue, though. > 2) If I want to send 100 KB of data from a client to server, > and that't the only connection (only one client to connect to > the server) what should I use for a ClientType and what for > a ServerType. Again, that depends on your actual needs and program design. > a) What technique of sending should I use for this? You need to provide more details about what exactly you are trying to accomplish in the first place. > c) When some error occur while process of sending data, > is some kind of immediate retry of the whole process of any sense? That depends on the particular error. > d) How can I know that the data has been sent > successfuly in this case? You usually don't. If you call a sending function and it doesn't produce an error, then you can rest assured that the socket stack accepted the data into its internal buffers for transmission at a later time. Whether the buffered data actually reaches the other side of the connection is another matter, and one that you won't know unless there is an acknowledgement packet implemented in your communications, so that the receiver can tell the sender if/when data has arrived. > 3) When sending up to 100 bytes of ASCII string from only > one client to server, should I use SendText() insted of SendBuf()? It doesn't matter much since SendText() simply calls SendBuf(). What you do have to worry about in either case, however, is whether the full 100 bytes are accepted in one pass, or if you have to call SendText/Buf() multiple times when the data can't be sent in one piece. Both SendText() and SendBuf() return the number of bytes actually accepted for transmission. If less than 100, then you have to re-call SendText/Buf() passing in the remaining unsent data. > a) Why SendBuf() is usualy recomended one? There is less indirection involved, and also because SendBuf() is the primary function that actually passes the data to the socket stack. > b) Should I use the same ClientType and ServerType like in > point 2 ? It doesn't matter whether the client and server use the same threading model or not. That is completely independant on both ends of the connection. Clients have no concept of (and doesn't care about) whether the server is blocking or non-blocking, and vice versa. > 4) If I have two (or more) clients that in some moment (mabe the > same) wants to send the data (max 20 KB) to the client Do you mean to the server? > what ClientType and ServerType should I then use? It still doesn't matter much. The server will still recieve the data from both clients. That is why the server's event have a Socket parameter, so that your code can know which client the incoming data is coming from when received. > a) What technique of sending should I use? (I think > maybe of TWinSocketStream). TWinSocketStream only applies to blocking connections. Whether you use blocking or non-blocking is, again, depending on your actual needs and design. > b) How can I know that the data has been sent > successfuly in this case? See further above. Gambit
Re: {ctNonBlocking, ctBlocking} and {stNonBlocking, stThreadBlocking}
Author: Vladimir Stefanovic
Date: Sat, 14 Aug 2004 09:50
Date: Sat, 14 Aug 2004 09:50
49 lines
2823 bytes
2823 bytes
Hi,
> You need to provide more details about what exactly you are
> trying to accomplish in the first place.
I'm curently in a process of coding a monitoring and survaillance
system which monitors some LOG files for changes (on different
server PCs), then finding some patterns to appear, and finally
informing some users via SMS, Email and LAN (I made custom
messenger for LAN).
The core of the system consists of 6 independent services, and many
other config apps. Some of the services should be installed on client's
machines, for example service which waits for data to show a custom
LAN message I menioned before. Email has it's own infrastructure on
client's machines, of couurse, same as Mobile phones. All other services
are on server machines.
So there are many socket connections to be wired in propper way in
the system.
I would be delighted if I could with your assistence resolve one case
for now. This is it:
One service (client socket) has a list of IP addresses and one-string
messages (up to 100 bytes) to be sent to (server socket) PCs which
are identified by the IP.
That means - client side /simplified/:
// Communication Ports are nagotiated before
for ( int i=0; i<List->Count; i++ )
SendViaSockets ( List->GetToIP( i ), List->GetMessageToSend( i ) );
If it is of any importance - IPs can repeat in the list.
On the server side, service should receive the message and show it to
the user. I know how to show the message, but I do not know how to
receive it in propper way because of:
> What you do have to worry about in either case, however, is whether
> the full 100 bytes are accepted in one pass, or if you have to call
> SendText/Buf() multiple times when the data can't be sent in one piece.
Can you please provide me some code to start with?
Best regards,
Vladimir Stefanovic
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads