Login  
Search All Forums
Dart Home | PowerTCP Sockets for .NET | Custom Development Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
AuthorForum: PowerTCP Sockets for .NET (Secure and Standard)
Topic: Best practices for read data from Server
Smoke

From: Mvd, Uruguay
Posts: 8
Member Since: 08/26/03
posted August 26, 2003 7:20 PM

I have posted a topic a few ago about how to connect mi clients to my server application and far away im doing good things...

My problem now is to read some data from my Server stream...

Basically, my client application can send me a string or an array of bytes...

For example, when my server send a "Date" command to my client my client just do a TCP.Send(Now) to me, so i get that string...
In the other hand i do a "get c:\pepe.txt" and my client read that file locally in a stream of bytes and then pass the bytes to me, but im having problems reading them, looks like i cant determine where to start and where to stop the reading the file...

Do i have to clear the readed information from the stream of my server? something like e.tcp.Stream.Flush or something like that?

What are the best way to read the data that’s come to the server and make sure you are not reading it twice or missing characters?

I have been looking on the examples but i didn’t find any useful that sweet my needs, since the only which server component is the Web Server and it does not what i need...

My idea is be able to provide my clients to function to send me the logs of the program automatically without their interaction, as well as some basic strings like version number, windows version, free disk space and so on, and my server will listen on a port to my clients to connect and i will send the commands as need...


Thanks a lot for the help and sorry for the many question, im just trying this product out to see if it fits our needs and it looks like it does, i just need time to learn how to use it :)
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted August 26, 2003 7:33 PM

You are basically writing your own protocol. You have to have some way of telling the client that the transfer is done. The easiest way I can think of would be to respond to the "Get" with 1 line containing the number of bytes that you are going to send, followed by the actual bytes of the file.

At the client send the request, then receive up to the first CRLF. From that get the byte count, then receive that many bytes and write the result to the local file.

Everything you need to do is in one or all of the samples. You just have to look for it.
Smoke

From: Mvd, Uruguay
Posts: 8
Member Since: 08/26/03
posted August 26, 2003 7:43 PM

Thanks for the help, i promis not to post more stupid question and take more in deph look to the samples and help :)
bronze

From: são paulo, Brazil
Posts: 5
Member Since: 03/11/04
posted March 11, 2004 3:09 PM

I have got a problem…I send, for example, 400bytes, and when it is to be read in the server, it stops…
And it only works back again when I use TCP1.close() in the client
 
In the event Server1_Connection
Do While (e.Tcp.Connected)
      Dim _bufferreceived() As Byte = New Byte() {}
 
      _bufferreceived() = e.Tcp.Stream.ToArray()
Loop
 
If I use, on the server,
 
s = e.Tcp.Receive.Buffer()
 
it only returns me 8kb
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted March 11, 2004 3:22 PM

In the future, please post new questions as new topics. This isn't really a follow-up to the previous post.

To answer your question:

If you sent 400Kb, you should expect to have to call receive about 50 times. As you have discovered, you'll usually get around 8K per call to receive. That is normal.

Please take a look at the sample apps and see if they work. Try sending 400k to the echo server sample and see what happens.

If you still have questions, please start another topic.

bronze

From: são paulo, Brazil
Posts: 5
Member Since: 03/11/04
posted March 15, 2004 8:18 AM

thanks for your help

:>))

Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX