Comments (6)
I will close this issue for now, as the subject on topic has already been answered. Thank you!
from ldpl-socket.
If I'm not wrong, socket read from $ in $ is blocking. This is not good for apps that depend on constant data reading from the socket, like an IRC client. … What do you think?
Yes you're right. It's blocking only, so I just added two statements to set a socket's state:
SOCKET SET BLOCKING <socket>
SOCKET SET NONBLOCKING <socket>
By default all sockets will still be blocking, but now you can do this:
socket connect to host at port in sock
display "~ Connected to " host ":" port " on " sock crlf
socket set nonblocking sock # <~~~~~
socket read from sock in msg
if errorcode is less than 0 then
display "err: " errorcode crlf
else if errorcode is greater than 0 then
display "err: disconnected" crlf
else
display "msg: " reply msg
end if
I wanted to keep a single SOCKET READ
command and not split it up into variants, as we may have to add more settable flag options in the future if people use this library for more things.
from ldpl-socket.
We will probably want to add select()
at some point too, for handling multiple nonblocking connections at once.
from ldpl-socket.
Yes you're right. It's blocking only, so I just added two statements to set a socket's state
Ah, wonderful! Better this way, I agree that more flags could be added in the future, so this is the cleanest approach. Yesterday I wrote a very dirty, small IRC client using your library and it worked as a charm, I was so excited haha! Great work.
We will probably want to add select() at some point too, for handling multiple nonblocking connections at once.
I didn't quite understand this, at the moment the library cannot connect to multiple servers or what's the problem here?
from ldpl-socket.
I agree that more flags could be added in the future
👍
Yesterday I wrote a very dirty, small IRC client using your library and it worked as a charm, I was so excited haha! Great work.
That is awesome! I will definitely try it.
at the moment the library cannot connect to multiple servers or what's the problem here?
It can, but you have to decide when to read from each socket on your own. There might not be any data there to read. With select()
you can hang and listen to a bunch of socket file descriptors at once, and it'll return when one of them is ready (or disconnects or something). It's what ldpl-net-server does when listening for clients.
Did we have this conversation already? I just had deja vu...
I think people use epoll()
or a library like http://software.schmorp.de/pkg/libev.html when doing any heavy duty network programming nowadays, but select() works and is simple and already on most systems as far as I know.
from ldpl-socket.
I think we had this conversation when we were talking about implementing sockets some months ago, haha. It's a good idea to implement some sort of select, I didn't really know that was even a thing!
I'll look into it when I have some free time 😉
from ldpl-socket.
Related Issues (4)
- IPv6 support HOT 1
- onDisconnect HOT 4
- URL support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ldpl-socket.