![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Questions & Help Needed Post any question regarding Basic4ppc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
||||
|
Hello!
Thanks, agraham, for your last threads. I think, I have to take another way. So, i have a new idea. Is it possible to run a seperat small application in the backround that takes the data from the server and send this data to the main application? So the small application can stop, when it is waiting for data without lock up the main program. ![]() ![]() |
|
||||
|
I would try using my Threading library Threading library for optimising compiler to run what is presently your timer code on a thread passing the data to the GPS. The GPSDecoded event is thread safe and will tell the rest of your code that data has arrived. Your thread can use Sleep() to determine the approximate rate you want to check DataAvailable. You should use RunLock in both main program and thread to access the GPS object.
I can't help but think there is something wrong somewhere - you shouldn't need to go to these lengths to get it to work ![]() |
|
|||
|
Hello schimanski,
i just flew over your code. From what i can understand so far, your problem is that you queue up data from the server if you don't read the net buffer for a while. I don't know what kind of server this is and what protocol it's using, but my first guess is, to just close the connection if you don't want to read data anymore. If you request data from the server and the server is sending reply data to your request continously, it is obvious that you need to read all reponses before you can get to the newer data.Furthermore, new data will be on the end of your buffer and therefore if you just read the first bytes / characters of your buffer you will always get the last server reponse the client received when it stopped reading from the stream. Receivebuffer: NMEA sentence 1, NMEA sentence 2 You read the sentences and therefore the buffer is now empty. Server sends new data and you read the receivebuffer constantly.The data in the first characters / bytes is always current due to this. You stop then reading the stream.After 2 minutes you start to read the stream again. The receivebuffer does now look like this: NMEA Sentence 1 ( 2 minutes old !) NMEA Sentence 2 ( 2 mins - 1sec) NMEA Sentence 3 ( 2mins - 2 secs.) If you now just look at the first characters / bytes of your buffer, you will see only the old data, to get newer data sentences, you have to look at the end of your buffer, for example by searching strings or characters. cheers TWELVE |
|
||||
|
Hello TWELVE!
Thanks for your fast answer, but that was not the problem, which I mean. Sorry, there are al lot of problems in my thread. ![]() I mean this: PHP Code:
Is there a way to write another sub with a counter etc.? The device is connected with the server over an GPRS-connection. m.f.G. schimanski |
|
||||
|
Quote:
Quote:
Quote:
From my point of view this can never happen, because the filestream.ReadString is only called if the client.DataAvailable condition is true.It can happen, if you don't use the client.DataAvailable thing and just try to read the stream.If there's data you will get it, if not, the .readstring will lock until data arrives the net buffer. Since the timer3 is only called every half or full second, the main app would not get locked entirely - if there's no deadlock condition within the timer3 code as described by you.If the receiving of data takes a notable amount of time ( and this is the case without doubt when GPRS is used..) , the main app freezes during this time. Multi-Threading as suggested by agraham would help out here only, if there's no deadlock condition ( ReadString is just waiting and has a chance to get read new data from the stream ever ). But certainly the exact behavior of this code depends on the latency/speed of your internet connection.If the connections needs 20secs. to retrieve the data, the Main App / GUI gets blocked for this period of time. So, my question is: does it really deadlock or just block for a couple of seconds...? If there's a main app and a code part, that is transfering data from/to internet , it is always a good idea to have that run in parallel ( threading, OS callback etc..) because of the freeze effects.Since Basic4PPC is not able to handle threading, this can only be achieved with agraham's threading lib. Quote:
I don't think you have to struggle here with the issue i described in the telnet client thread, because in that case your "If client.DataAvailable=true Then" would not become true and therefore the code just would not read from the stream.My code works different, because of the used protocol.I send commands to the server and expect a certain reply to this. regards TWELVE |
|
||||
|
Quote:
You're so right. I see, that the problem isn't dataavailable. I don't have any authority to the server-code, so I think, that I have to life with this problem. So much thanks to you, TWELVE and AGRAHAM, for your efforts. ![]() |
|
||||
|
This DataAvailable has been worrying me. I have googled around and found a very few instances of other people suffering similar reliability problems with DataAvailable so I have thought of a possible workaround. This needs .NET 2.0 and the Door library. It relies on setting the ReadTimeout of the Stream to a small number then calling Read which then throws an exception on timeout or returns the number of bytes read. I have tried the following code in a real application and it works for me. However I have not experienced any DataAvailable problems myself so I do not know whether this technique will sidestep any problems or not. Anyway being able to try a read and not block if it fails can't help but be a good thing.
Code:
' globals
Count = 0 ' count of bytes received
Dim WebResp(4096) As Byte ' read buffer
Sub DataAvailable
ErrorLabel(DAerr)
count = Stream.ReadBytes(WebResp(),4096)
Return true
DAerr:
Return false ' if the Read times out it throws an exception
End Sub
Sub NetGetData(req)
msg ="An error occurred connecting to " & URL
ErrorLabel("err2")
Client.New1
Client.Connect(URL, Port)
Stream.New1(Client.GetStream,true)
StreamObj.Value = Client.GetStream 'StreamObj is a Door library Object
StreamObj.SetProperty("ReadTimeout",1) ' set the Read stream timeout to 1 mSec
msg = "GET /" & req & " HTTP/1.1" & Crlf
msg = msg & "Host: " & URL & Crlf
msg = msg & "Proxy-Connection: Keep-Alive" & Crlf
msg = msg & "Pragma: no-cache" & crlf
WebReq() = Stream.StringToBytes(msg)
Stream.WriteBytes2(WebReq(),0,StrLength(msg))
Timer = 0
Do
Sleep(SleepMs)
Timer = Timer + SleepMs
If Timer >= Timeout Then
Return "A timeout occurred communicating with " & Device
End If
Loop Until DataAvailable
msg = Stream.BytesToString (WebResp(), 0, Count)
Client.Close
Return msg
End Sub
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| One server adn more clients | Byak@ | Questions & Help Needed | 2 | 08-12-2008 11:59 AM |
| Comunicating with a Telnet Server | lu_ozzie | Questions & Help Needed | 16 | 05-05-2008 06:25 PM |
| Simple NMEA logger | Bruno | Share Your Creations | 0 | 05-02-2008 08:43 PM |
| Checksum in nmea | wolfgang | Code Samples & Tips | 0 | 02-15-2008 02:42 PM |
| New server | Erel | Forum Discussion | 12 | 11-06-2007 05:21 PM |