Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:33 29 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : tcp server - what am I doing wrong ?

Author Message
kaptinvimes
Newbie

Joined: 07/08/2022
Location: United Kingdom
Posts: 11
Posted: 09:57am 20 Mar 2023
Copy link to clipboard 
Print this post

Having some trouble with Option tcp server port 80
When I send this to picomite

OPTION wifi "xxxx","xxxx"
OPTION tcp server port 80
All is good and web ntp works as expected.

However when I send this

OPTION wifi "xxxx","xxxx"
OPTION tcp server port 80

Dim buff%(512)
Dim buff1%(512)

PRINT
PRINT "Your IP address is : " + MM.Info(ip address)
PRINT
WEB tcp interrupt serverstart
Do
  randomnum = Int(Rnd(100)*100)
Loop
Sub serverstart
Local p%, t%
For a%=1 To MM.Info(MAX connections)
    LongString CLEAR buff%()
    WEB tcp READ a%,buff%()edit
    p%=LInStr(buff%(),"GET")
    t%=LInStr(buff%(),"HTTP")
   s$=""
   If (p%<>0) And  (t%<>0) And (t%>p%) Then
     s$=LGetStr$(buff%(),p%,t%-p%+4)
     Print "String is ",s$
   EndIf
   If Instr(s$,"HTTP") Then
     Print "sending page"
     WEB transmit PAGE a%,"second.html"
   EndIf
Next a%
End Sub

Server appears to start Ok however program just hangs and access to ip address in browser is refused.

The only way to get this to work is to send

OPTION wifi "xxxx","xxxx"
OPTION tcp server port 80

and then send


Dim buff%(512)
Dim buff1%(512)

PRINT
PRINT "Your IP address is : " + MM.Info(ip address)
PRINT
WEB tcp interrupt serverstart
Do
  randomnum = Int(Rnd(100)*100)
Loop
Sub serverstart
Local p%, t%
For a%=1 To MM.Info(MAX connections)
    LongString CLEAR buff%()
    WEB tcp READ a%,buff%()edit
    p%=LInStr(buff%(),"GET")
    t%=LInStr(buff%(),"HTTP")
   s$=""
   If (p%<>0) And  (t%<>0) And (t%>p%) Then
     s$=LGetStr$(buff%(),p%,t%-p%+4)
     Print "String is ",s$
   EndIf
   If Instr(s$,"HTTP") Then
     Print "sending page"
     WEB transmit PAGE a%,"second.html"
   EndIf
Next a%
End Sub

And then all works as expected with web access to ip address established and page accessable. If Picomite is powered down when exercise has to be repeated on restart.

Any ideas gratefully received ! thank you
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9139
Posted: 10:33am 20 Mar 2023
Copy link to clipboard 
Print this post

The option commands permanently set up the Pico and can only be executed at the command prompt and only need doing once - they should never be included in a program.
 
kaptinvimes
Newbie

Joined: 07/08/2022
Location: United Kingdom
Posts: 11
Posted: 11:56am 20 Mar 2023
Copy link to clipboard 
Print this post

Thanks for that, I had forgotten -
(also left Option Autorun On out)
Still all good now
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024