Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC:

WebServer dont work with 2.12 01 Jul 2022 21:06 #22941

  • Horst
  • Horst's Avatar
  • Topic Author


  • Posts: 293
  • Hello
    With the help of this community i build a little WebServer. Instead to use IIS or Apache. It works very well.
    Now i compiled it with 2.12 and the WebServer starts. When i open the browser and type localhost nothing happen any more.
    This little WebServer is the core/heart of my App.
    So i need help !! Because i dont know how this core realy works :-) and i think its a XSharp bug.

    Horst
    Attachments:

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 02 Jul 2022 11:33 #22947

    • ic2
    • ic2's Avatar


  • Posts: 1661
  • Hello Horst,

    Your zip doesn't seem to contain X# code? What do you expect us to test or check?
    I also noticed a server.log with messages like Die Datei "C:\WebServer\error.html" konnte nicht gefunden werden..

    Did you notice that and does this explain some of your issues?

    Dick

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 02 Jul 2022 12:10 #22948

    • Horst
    • Horst's Avatar
    • Topic Author


  • Posts: 293
  • Hi Dick
    Its a Xide VIAEF file into the zip. i thought thats ok.
    The logfile is not relevant for this error. the program will not call any thread when its compiled by x# 12.2

    PRIVATE METHOD HandleRequests() AS VOID
    LOCAL context AS HttpListenerContext
    SELF:httpListener:Start()
    TRY
    WHILE SELF:httpListener:IsListening
    Console.WriteLine("The Linstener Is Listening!")
    context := SELF:httpListener:GetContext()
    SELF:messages:Add(context)

    Console.WriteLine("The Linstener has added a message!")
    END WHILE

    CATCH e AS Exception
    Console.WriteLine(e:Message)
    END TRY

    i think , the bold text is not working anymore.
    in my example compiled with x#10c the browser will show index.html and crash. the crash is ok because i made the example small as possible,
    but compiled with x# 12 the browser is the whole time waiting for response and will not show the index.html.

    WebServer.exe has to run as admin with the parameter -80
    Sorry ist hard to explain. ;-)
    Horst

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 03 Jul 2022 05:55 #22951

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Horst,
    first of all: I don't think anyone can help you with incomplete code.
    To have a help, first of all your sample has to be complete and you have to deliver instructions how to build and run in.
    On my machine, the library does not build because QRCoder.dll is missing.
    Do you have tried to debug your executable, maybe using System.Diagnostics.Debug.Write() methods?
    But nevertheless, I have been able to compile and run your code.
    A few points:
    - it is bad code to don't test if any parameters are passed to your program
    - why you are starting your listener outside the try-catch block? So if there is any exception in this code, your application will crash
    - write errors to the console does not helps a lot, it may be a lot better to write them also to a file
    But anyway, on my machine it works:

    I have to admit that I don't run the 2.12 compiler, but a newer prerelease version.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 03 Jul 2022 12:19 #22952

    • Horst
    • Horst's Avatar
    • Topic Author


  • Posts: 293
  • Hallo Wolfgang
    This listener is build with some of your code and help/code of others.
    As i said, i dont know realy what it does :-) My part starts with the response method - the simple clipper code ;)
    i have no experience when it goes to close to the machine.
    So for any advice to make it more stable i am realy happy.

    in the attachement i tryed to make a better sample (less code) , when you can compile and run it , and the "hello world" comes so all is ok, i can wait till x# 2.13 :-)

    Horst

    ps:
    1 - in the zip is a readme file - do you think its ok like that for others to let it run ?
    2 - i dont know to explain how to compile , is it not in the viaef file included ?
    Attachments:

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 03 Jul 2022 20:32 #22953

    • ic2
    • ic2's Avatar


  • Posts: 1661
  • Hello Horst,

    Horst wrote: Its a Xide VIAEF file into the zip. i thought thats ok.


    Probably, as Wolfgang got it working. I understand that this is a Xide variation on the VO AEF file(s) but I have no idea how to run this. It doesn't start to run with F5 or Shift F5, I can's set breakpoints, etc. You limit your audience to those familiair with Xide. If it contains a product file it should probably run in Xide also for those not using Xide, like me.

    There is also no Readme in the zip (I checked the zip of your second upload)

    Dick

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 04:54 #22954

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Dick,
    personally I think that everyone that uses X# should also have XIDE installed - even if not used in production it is the best environment for test code, for a small library or a console executable.
    And it also gives the possibility to transfer code using export files like VO.
    Wolfgang
    P.S. there IS a readme.txt in the second zip
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 05:10 #22955

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Horst,
    personally I think you should try to understand what you are writing and using.
    A few samples how code should not be:
    function Start (args as string [] ) as void
    Console:WriteLine(args [1])
    If someone tries to start your executable without parameters, it will terminate with a runtime error.
    IMHO you should write code like this
    if args:Length > 0 .and. args[1]:Length >= 2
       cArg := args[1]
    else
       cArg := "-80"
       Console.WriteLine( "Error: application has to be started with the port as parameter '-80' is the default" )
    endif
    Console:WriteLine(cArg)
    Another sample, as I wrote before:
    private method HandleRequests() as void 
    local context as HttpListenerContext
    self:httpListener:Start()
    try
    while self:httpListener:IsListening
       Console.WriteLine("The Linstener Is Listening!")
       context := self:httpListener:GetContext()
       self:messages:Add(context)
       Console.WriteLine("The Linstener has added a message!")
    end while
    catch e as Exception
    Console.WriteLine(e:Message) 
    end try
    You yhould move the "self:httpListener:Start()" inside the try - catch block because otherwise you will not be notified if the application gives a runtime error inside that statement:
    private method HandleRequests() as void 
    local context as HttpListenerContext
    try
    self:httpListener:Start()
    while self:httpListener:IsListening
       Console.WriteLine("The Linstener Is Listening!")
       context := self:httpListener:GetContext()
       self:messages:Add(context)
       Console.WriteLine("The Linstener has added a message!")
    end while
    catch e as Exception
    Console.WriteLine(e:Message) 
    end try
    I'm far away from being an expert in the .NET Framework programming, so my samples are far from being perfect, but they should give you an idea what you can make better.
    Wolfgang
    P.S. and yes, when compiled with X# the output is shown in the browser, but there is also a runtime error:
    05:07:11 Processor 1 crashed. System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
       bei Service.HttpServer.Response(HttpListenerContext ocontext) in C:\XSharp\XIDE\Projects\TestProject\Applications\WebServer\Prg\HttpServer.prg:Zeile 245.
       bei Service.HttpServer.Processor(Int32 number, BlockingCollection`1 messages) in C:\XSharp\XIDE\Projects\TestProject\Applications\WebServer\Prg\HttpServer.prg:Zeile 91.
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 09:11 #22956

    • Horst
    • Horst's Avatar
    • Topic Author


  • Posts: 293
  • Hallo Wolfgang

    I see, i tryed to catch der arguments on the wrong place and i will change that.
    PUBLIC METHOD Start(port AS STRING ) AS VOID
    LOCAL i AS LONG
    // Falls ohne Parameter gestartet-  Standartport 8080 nehmen                   
    IF Empty (port) ; port := "80" ; ENDIF
    SELF:listenerLoop := Thread{HandleRequests}
    SELF:httpListener:Prefixes:Add( "http://*:"+AllTrim(port)+"/") //hk

    And now i see also witch line of code i have to move into the try :-)

    The runtime error is wired because its only happend when you type localhost at the first time , type it again (while the app is still running) no runtime error appears.

    When i compile i have 1 warning
    warning XS0165: Use of unassigned local variable 'bBuffer'
    LOCAL bBuffer  ?? 	AS BYTE[]
    and its a shame, i dont know how to assign a byte

    About debug. is it right, this app i cant let it run with the debugger ? Thats why also Dick cant let it run with F5 in the IDE.

    And i am happy it works with your newer version of X#, i was realy shocked when the core of my app was no more working.

    Thanks for your help
    Horst

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 09:49 #22957

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Horst,
    about assigning a value to a byte array ( byte[] ), you can find that information here:
    docs.xsharp.it/doku.php?id=string_char_byte
    And for debugging purposes you can also start your executable and attach the Visual Studio Debugger to your running executable.
    But debugging is not only using a debugger, but can also be done writing to the debug port or to log files.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 10:48 #22959

    • Horst
    • Horst's Avatar
    • Topic Author


  • Posts: 293
  • Hallo Wolfgang

    the compiler is comlaining because the assign of the byte is in the if-endif
    LOCAL bBuffer 			AS BYTE[]
    if 
        bBuffer := System.Text.Encoding.UTF8:GetBytes( cString ) 
    endif
    ocontext:Response:ContentLength64 	:= bBuffer:Length
    what i mean with i dont know how to assign a byte is like:
    Local cString := "" as string
    so i tried this and it seems ok (found in the link you send me ).
    Local bBuffer := Byte[]{0} as byte []

    Horst

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 11:38 #22960

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Horst,
    the compiler is completely right here because exactly this code also gives an error at runtime.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 20:55 #22968

    • ic2
    • ic2's Avatar


  • Posts: 1661
  • Hello Wolfgang,

    wriedmann wrote: ,
    personally I think that everyone that uses X# should also have XIDE installed - even if not used in production it is the best environment for test code, for a small library or a console executable.
    And it also gives the possibility to transfer code using export files like VO.


    Of course I have Xide installed and I wish I could use it for everything, which I can't so I am condemned to use VS. But that also means that everything which does not work like VO or VS could be crystal clear for Xide users but not for others.

    I have no idea how to handle a viaef file. In VO I would select a repo and then File/Import. This command isn't present in Xide, File/Open does not select viaef files and doubleclicking on it does not run it. And it's not documented when I search in the help on viaef.

    I directly admit that Xide is a genius piece of work. But without experience how to use it, I am afraid I am not the only one who gets stuck.....

    DIck

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 21:26 #22970

    • FFF
    • FFF's Avatar


  • Posts: 1419
  • Godness, Dick,
    aef is short for application export file. So, open any project in Xide, rightclick on its name in the treeview, hit IMPORT Application, and select the aef.
    Regards
    Karl (X# 2.15.0.3; Xide 2.15; W8.1/64 German)

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 22:04 #22972

    • Chris
    • Chris's Avatar


  • Posts: 3974
  • ...or use Application->Import Application

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 22:25 #22973

    • ic2
    • ic2's Avatar


  • Posts: 1661
  • Hello Karl,

    FFF wrote: Godness, Dick,


    That's too much honour. You may just call me Dick :P

    FFF wrote: aef is short for application export file.


    I know that, for over 20 years now.

    FFF wrote: So, open any project in Xide, rightclick on its name in the treeview, hit IMPORT Application, and select the aef.


    Thanks for explaining.

    Compared to VO: VO always opens with a project, even a newly VO would open with a Default project with the standard libraries. Then the Import option can be found in the File menu.

    In Xide I have the Empty Placeholder which doesn't work for importing viaef files. I also have another project which seems normally present in the indicated directory but first, after opening, nothing is there, see picture:

    On the main screen I can't remove it because nothing happens when I click the Remove button.

    Chris' suggestion to use Application->Import Application sounds a lot more logical and easier.

    No doubt, knowing Chris, Xide works more logical than VS (what isn't) or VO. But I maintain that when you are used to VS or VO it's less straightforward to use Xide than you seem to think.

    DIck
    Attachments:

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 04 Jul 2022 22:29 #22974

    • Chris
    • Chris's Avatar


  • Posts: 3974
  • Hi Dick,

    For this "orphan" project in the list, please open the XIDE.cpc file in the main XIDE folder with a text editor and remove that bogus entry.

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 05 Jul 2022 11:46 #22980

    • ic2
    • ic2's Avatar


  • Posts: 1661
  • Hello Chris,

    Thanks, that works. I am not sure why & how it was added to Xide, there's no .sln file there either. It was a project to test setting the WebView2 to a customcontrol so nothing important.

    I should spend some time on Xide I think B)

    Dick

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 05 Jul 2022 11:52 #22981

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Dick,
    I should spend some time on Xide I think
    that is always a good idea, specially for testing purposes. For these, I'm starting normally from the Basic X# application.
    Wolfgang
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it

    Please Log in or Create an account to join the conversation.

    WebServer dont work with 2.12 05 Jul 2022 17:19 #22983

    • Chris
    • Chris's Avatar


  • Posts: 3974
  • Hi Dick,

    There's no .sln, because XIDE uses a completely custom project file format, it cannot read .sln files which are used by VS, and of course VS cannot read the project files of XIDE. For this reason I had told you it is not easy to share projects/code from both VS and XIDE at the same time. Doable, but since you're already used to VS now, I think it's best to stay with it. But yeah, does not hurt to be a little familiar with XIDE, too..

    .
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1
    • 2