Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket Implementation #110

Closed
milisarge opened this issue Jun 1, 2019 · 10 comments
Closed

Socket Implementation #110

milisarge opened this issue Jun 1, 2019 · 10 comments

Comments

@milisarge
Copy link

Have you a plan to implement sockets in Ldpl?, that will be awesome to start coding some network protocols, maybe a telnet or basic HTTP server...

@Lartu
Copy link
Owner

Lartu commented Jun 1, 2019

@dvkt you have more experience than I do with this. Would it be possible to add some kind of socket statements to LDPL?

@xvxx
Copy link
Collaborator

xvxx commented Jun 2, 2019

Would it be possible to add some kind of socket statements to LDPL?

Definitely! We could start with something simple and grow from there.

Maybe three statements: one to send, one to receive, and one to reply.

Send statement:

SEND <TEXT-EXPR> TO <TEXT-EXPR> AT <NUMBER-EXPR> IN <TEXT-VAR>

Receive statement:

LISTEN ON <TEXT-EXPR> AT <NUMBER-EXPR> AND CALL <SUB-PROCEDURE> WITH <TEXT-VAR>

Reply statement:

REPLY WITH <TEXT-EXPR>

Here's what a Gopher request would look like:

send crlf to "gopher.black" at 70 in response
display response crlf

Raw HTTP request:

in request join "GET /get HTTP/1.1" crlf "Host:httpbin.org" crlf crlf
send request to "httpbin.org" at 80 in response
display response crlf

Echo server:

sub-procedure echo-handler
    if data is equal to "shutdown" then
        exit
    else 
        reply with data 
    end if
end sub-procedure

listen on "localhost" at 12345 and call echo-handler with data	

Echo client:

display ">> "
accept request
send request to "localhost" at 12345 in response
display "== " response crlf

I think that would get us pretty far. We'd maybe also want to add variants for local sockets, that don't assume host and port. I don't know a lot about sockets on Windows but I am sure we could make this cross platform. (The statements could be anything, this is just one idea to see if it would cover the bases or not.)

[[ Edit: Oh I guess sockets are pretty similar on Windows! Great. ]]

@Lartu
Copy link
Owner

Lartu commented Jun 2, 2019 via email

@Lartu Lartu added the feature request Please add this to the language! label Jun 17, 2019
@Lartu Lartu modified the milestone: LDPL 3.0.7 'Eloquent Eoraptor' Jun 20, 2019
@Lartu
Copy link
Owner

Lartu commented Aug 19, 2019

Some socket support has been added using the LDPL Net Server library. A net client library has yet to be made, but this is a step forward towards the completition of this issue.

@Lartu Lartu added library required and removed feature request Please add this to the language! labels Oct 3, 2019
@Lartu
Copy link
Owner

Lartu commented Oct 3, 2019

A socket client library for LDPL should have the following things:

  • It should expect an socket_new_message sub to be declared by the user, to handle new messages.
  • It should expect an socket_on_conneect sub to be declared by the user, to be executed when a socket connects to somewhere.
  • It should expect an socket_on_disconneect sub to be declared by the user, to be executed when a socket is disconnected.
  • It should provide a socket <socketNumber> connect to <ip> port <port> to create and connect a socket to a server.
  • It should provide a socket <socketNumber> disconnect to close a socket connection (and free it).

@xvxx
Copy link
Collaborator

xvxx commented Nov 14, 2019

Well, it took me a few months, but I've got another attempt at this based on all the new features in LDPL and Lartu's amazing ldpl-net-server project. It only works for simple reading/writing over TCP right now, but it's able to serve as an echo client to ldpl-net-server's echo server example:

https://github.com/dvkt/ldpl-socket

It also works with this simple echoserver in C as long as you modify it to close and reopen the connection after each echo message. So, that's two echo servers it works with. Production ready networking solution.

Instead of using callbacks, I just kept close to the C socket API. Since that API is synchronus, this package adds these synchronous LDPL statements:

  • SOCKET CONNECT TO <hostname> AT <port> IN <number variable>
  • SOCKET CLOSE <socket number>
  • SOCKET SEND <text> TO <socket number>
  • SOCKET READ FROM <socket number> IN <text variable>

As far as the library itself goes, maybe it should be called ldpl-net-client? Or the two should be merged into a ldpl-net package that can be community maintained, or in the std?

I'm going to keep testing this - it might be a dead end like last time, but since it's based on Lartu's code this time I have a good feeling about it!

@Lartu
Copy link
Owner

Lartu commented Nov 14, 2019

Holy sh*t you are alive 😱 welcome back! We've missed you!

It only works for simple reading/writing over TCP right now, but it's able to serve as an echo client [...]

This is wonderful! That's exactly what's needed right now!

I love the logo you made. I simply love it, haha. About the name of the library, I think ldpl-socket is perfect. It's 100% descriptive of what it is, so I'd leave it the way it is now.

I'm about to release (maybe today, it's already tested and working) an ncurses library for LDPL (used to make lute), so this comes extremely in handy! We can now write IRC clients in LDPL, MUD clients in LDPL, chat apps and whatnot! This is amazing! I'm super exited, I will test-drive it in some project asap!

Thank you for your awesome contribution, as always. I'll add a link to it (and to your todo app, that's also wonderful) to the LDPL website and the LDPL readme also asap. And again, welcome back! 🏖️

@Lartu
Copy link
Owner

Lartu commented Nov 14, 2019

And I will add your library to LPM, if that's ok with you.

@xvxx
Copy link
Collaborator

xvxx commented Nov 14, 2019

Thank you! I've missed everyone here too. Especially dino. 🦕

I love the logo you made.

haha, I'm not much of an illustrator. If you ever wanted to draw an upgraded logo in the style of the ldpl-net-server one that would be greatly appreciated. But this one has some charm.

I'm about to release ... an ncurses library for LDPL

That sounds great! LDPL would is a wonderful fit for terminal apps.

And I will add your library to LPM, if that's ok with you.

Yes that's great! Thank you. I just updated Gild to use the new socket library and it seems to work fine: xvxx/gild@de9e3d5

We can probably close this issue now and direct new issues (bugs) to the appropriate libraries. 👍

@Lartu
Copy link
Owner

Lartu commented Nov 15, 2019

We missed you too! LDPL has grown a lot since we last saw you here (we have a new website, LPM, we added multicontainers, etc) if you need help catching up or something do ask! 😄

haha, I'm not much of an illustrator. If you ever wanted to draw an upgraded logo in the style of the ldpl-net-server one that would be greatly appreciated. But this one has some charm.

I do really love you made though, haha. If you want I can upgrade it to the style of the other LDPL library logos (no problem at all), but this one is cute. Haha!

That sounds great! LDPL would is a wonderful fit for terminal apps.

We are trying to find a niche for it and I think that we've somewhat struck some gold here. Let's see how that evolves!

Yes that's great! Thank you. I just updated Gild to use the new socket library and it seems to work fine.

Woah, wonderful! I'm super excited to try your library, there are so many things I wanted to make with LDPL that required client sockets that we didn't have. No sleep for me tonight!

We can probably close this issue now and direct new issues (bugs) to the appropriate libraries.

I shall close this issue then. Once more, thank you for your marvelous contributions and welcome back!

@Lartu Lartu closed this as completed Nov 15, 2019
@Lartu Lartu reopened this Nov 28, 2022
@Lartu Lartu closed this as completed Nov 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants