Lartu / ldpl

COBOL-like programming language that compiles to C++. With serious dinosaurs with neckties and briefcases 🦕💼
https://www.ldpl-lang.org/
Apache License 2.0
158 stars 24 forks source link

Socket Implementation #110

Closed milisarge closed 1 year ago

milisarge commented 5 years ago

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 commented 5 years ago

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

xvxx commented 5 years ago

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 commented 5 years ago

Yes! This is wonderful! I couldn't have made it simpler, I love it. Yes, we could definitely do that!

Lartu commented 5 years ago

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 commented 4 years ago

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

xvxx commented 4 years ago

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:

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 commented 4 years ago

Holy sh*t you are alive :scream: 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! :beach_umbrella:

Lartu commented 4 years ago

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

xvxx commented 4 years ago

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: https://github.com/dvkt/gild/commit/de9e3d50f13811231e1b182cc09d12f807c5a889

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

Lartu commented 4 years ago

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! :smile:

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!