We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Disconnect the Client from the Server
#1
(translated by Google translator)

Hi all.
I don't know if I chose the right topic for my question.  Angel

Now, if I want to correctly disconnect the Client from the Server, then I can use the "LDGraphicsWindow.Closing" handler for the Graphics Window, but I do not see such a handler for the Text Window.

My question is: is this handler not needed when using the Text Window, or is such a handler just not yet created in the LD extension?

Thank you.
Reply
#2
Hi AB,

As a rule I generally think a new thread for a new question is best so I did split this one, but in the end it doesn't really matter of course.

I assume you want a client to inform the server that it is leaving.  To do this the client should call LDClient.Disconnect().  It is hard to know when the client may just end its program, hence the use of LDGraphicsWindow.Closing in one of my client-server examples for a GW based program.  In the case where the client only has a TextWindow which they may close to end the session, there is no equivalent to LDGraphicsWindow.Closing event for the TextWindow in LD extension.

It would be best if the client ended some way using LDClient.Disconnect(), but not essential if the server can cope with it.  We cannot get the client to send LDClient.Disconnect() if a user just kills it by closing TextWindow, but if it is being run by AI then it should end itself nicely with LDClient.Disconnect() when it is done, probably immediately before Program.End() is called.  Also, I assume the rabbit/snake program will be using GW.

In the case where a client can just 'disappear', the server could issue a command to all clients (say once a second) asking if they are still there and if the server gets no reply, then assume the client is gone.
Reply
#3
I see.

I want the client to disconnect from the Server correctly. I will definitely be using the Graphics Window for the Client since the Text Window don't let me disconnect before closing the Client program.

Thanks for the info.  Smile
Reply
#4
(translated by Google translator)

Hi all.
First I want to ask in principle, that is, without details...
Using the editor, I opened the file "LDClient.sb" from the "client-server" folder, which is located in the "LitDev_v1.2.27.0" archive.
Using code snippets from this file, I created my "Rabbit AI" client file. This file contains fragments of code for communication between the Client and the Server, which I copied from "LDClient.sb" and pasted into “Rabbit AI”.
When I run the example from the archive, everything works fine.
But, if I run my code, a Text Window appears that contains a message:
<>c__DisplayClass31_0.<set_ExitOnClose>b__0 : An object reference does not point to an object instance.  Huh

But at the same time, my program works well.

If without details, can you now advise what I can do to eliminate this nuisance?

Thank you.
Reply
#5
Hi,

Obviously without code I can reproduce issue with I can only guess, so here goes.

1] This error could maybe happen if the LDGraphicsWindow.ExitOnClose event is set before the GraphicsWindow is created.
2] Some error messages can be prevented using LDUtilities.ShowErrors = "False", but you should fix the error to expect it to work!
Reply
#6
You are right!  Smile
I just moved the lines of code to create the Graphic Window to the very beginning of the file and the problem disappeared.
   
Thank you very much!
Reply
#7
(translated by Google translator)

Hi all.
That's what I was thinking this morning.

The game "AI Snake" is a system that consists of three parts: Server "Nature" and two Clients "AI Rabbit" and "AI Snake".
I think that for the convenience of distributing the game, it is the best thing to have one file that contains the Server code and the fully commented “Template” code.
The "Template" code must implement high-quality communication between the Server and the Client and have a place where any developer can insert the code of their version of the Snake or Rabbit AI.
To do this, a new developer just needs to copy the “Template” code from the “Nature” code, then paste it into a new file of the future Client and uncomment the lines.
Of course, finished versions of client AI will be distributed as separate Small Basic files. But it is probably better to distribute the Client TEMPLATE in the Server code file, because the Template code takes up little space.

If I'm right, then please advise me what rules should a good "Template" code follow?.. After all, I am an absolute beginner.  Smile

Thank you.
Reply
#8
Sounds good, as long as the instructions are clear what to do, I'm sure there will be a few of us here that will have a go Smile .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)