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: Receiving data bigger then 8k with PowerTCP Sockets for .NET
FrankBusch
fbusch@gmx.net

From: Dormagen, Germany
Posts: 5
Member Since: 12/17/02
posted September 3, 2003 3:49 PM

Hi there

I'm trying to upgrade an application written with the PowerTCP-ActiveX-Server to the PowerTCP Sockets for .Net. I'm doing a Server that acts on recieved orders and data-packs from the client.
The server is listening and starts a client with each connection. The client is packed into a VB-class with

Private WithEvents mTCPConnect As Dart.PowerTCP.Sockets.Tcp

and a method invoked from outside like

mTCPConnect.AutoReceive = True
Do While mTCPConnect.Connected
 Threading.Thread.CurrentThread.Sleep(100)
Loop

I also put in a event-method like

Public Sub Receive(ByVal sender As Object, ByVal e As Dart.PowerTCP.Sockets.SegmentEventArgs) Handles mTCPConnect.EndReceive
 Static baGesamtdaten() As Byte
 Static iGesamtLang As Integer

 glStatRecieved += e.Segment.Count
 ReDim Preserve baGesamtdaten(iGesamtLang + e.Segment.Count)
 Array.Copy(e.Segment.Buffer, 0, baGesamtdaten, iGesamtLang, e.Segment.Count)
 iGesamtLang += e.Segment.Count

 If MsgCompleted(baGesamtDaten) Then
  ...even more code working with the data received
  iGesamtLang = 0
 End If
End Sub


With this frame everything is quiet perfect.
I get messages from the client, I recognize the message is completed and act on it.
But if the amount of data sent by the client gets bigger than 8192 bytes it doesn't work any longer.
I receive 8192 bytes and copy them to my collectbuffer.
I leave the method and it is called again presenting then same(!) first 8192 bytes again.
This is an endless loop and I never get anything except theese 8k.
With the ActiveX-PowerTCP-Server this worked quiet well because with every call of the receive-method I got the next data. Obviously this behaviour changed but I can't find any example how to transfer this.

Can anybody help me?

Thanks in advance

Frank
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted September 3, 2003 3:59 PM

What happens if you stop putting the thread to sleep? In fact what is the purpose of the code anyway?

Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted September 3, 2003 4:25 PM

Also, I found some code that once used that's kind of similar to what you are trying to do. You should take a look at this code ( which works for me ) and see what's different:

' This code connects to the Dart web site and
' saves the results of a GET operation to a file
' called "c:\result.txt"

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Button1.Enabled = False
    If System.IO.File.Exists("c:\result.txt") Then System.IO.File.Delete("c:\result.txt")
    Tcp1.AutoReceive = True
    Tcp1.Connect("www.dart.com", 80)
    Tcp1.Send("GET / HTTP/1.0" + vbCrLf + vbCrLf)
    Do While Tcp1.Connected
      Application.DoEvents()
    Loop
    Button1.Enabled = True
  End Sub

  Private Sub Tcp1_EndReceive(ByVal sender As Object, ByVal e As Dart.PowerTCP.Sockets.SegmentEventArgs) Handles Tcp1.EndReceive
    Dim Stream As New IO.FileStream("c:\result.txt", IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite)
    Stream.Seek(0, IO.SeekOrigin.End)
    Stream.Write(e.Segment.Buffer, 0, e.Segment.Count)
    Stream.Close()
  End Sub
FrankBusch
fbusch@gmx.net

From: Dormagen, Germany
Posts: 5
Member Since: 12/17/02
posted September 3, 2003 4:34 PM

The important thing is that I have a TCP-Control with AutoReceive.
If I just kill the Sleep-command and replace it with a Application.DoEvents() I increase then processor-usage to 100%. That's all what happens :)

What I want to do:
Within the Receive-method I want to get the data incoming over the specific IP-connection.
Then I decode theese data, act on them and send out an answer.

All this works fine as long as the data sent by the client isn't bigger than 8192 bytes.
If so, the e.Segment.buffer which is given as a parameter of the Receive-method always contains the first 8192 byte and I don't know how to get the rest of the message.
And this is exactly the problem I have to solve...

Frank
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted September 3, 2003 4:51 PM

I was not able to completely understand what you were doing in your receive event so let's leave your code out of this for now.

The code I posted should work for you. The data received is > 8192. Please try the code I posted and if it works, try to implement something similar in your project.

FrankBusch
fbusch@gmx.net

From: Dormagen, Germany
Posts: 5
Member Since: 12/17/02
posted September 4, 2003 4:48 AM

Thanks a lot for your help.
I finally found my bug :)
In my code I had a loop that caused me to work with the same data again and again (instead of leaving the method in order to be reinvoked with the next block of data)
After taking a look to your code I new that the basics of my code were correct and so I was able to find what was wrong.

Thanks again :)

Frank
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted September 4, 2003 9:29 AM

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