Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
meigrafd

running TCP Socket in background?

Question

Hello.

 

Is it possible to run a Program (Daemon) in the Background, listening for TCP Connections ?

 

I read something about that its possible to have 4 threads (background tasks?) and i saw the linux like 'rc' stuff in OpenOS...

 

 

The intension is to have something like a relay script:

Daemon Script listens on special port for Connections; any Client-Script on same computer connects and if the Client then sends a special message the Daemon will relay it to IRC  ;)

 

...i want to write a Script to control something and already have a while loop - and dont want to connect&send&disconnect; connect&send&disconnect etc. to irc each message  :unsure:

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 0

OpenOS has no such thing as "background processes" - really all code is executed in a single thread. What you probably want is the event library's listen function, which allows you to register a listener that is called when the computer receives a given signal type.

I'm not sure if this works any differently with TCP sockets, I have no idea how to use those even in real life code. Someone else probably knows though.

Link to post
Share on other sites
  • 0

rc allows you to manage "service"-like programs in /etc/rc.d, control which ones are started on boot, and lets you send commands to the services. It doesn't provide any way of running programs in the background.

process is used to load other executable files as coroutines and keeps track of what program a coroutine was created by. process.load returns a normal coroutine, which you still have to run yourself. In Lua there can only be a single running coroutine at a time, which means that you cannot make background processes with this either.

 

event.listen doesn't create any background processes either. It lets you register functions that are called whenever a certain signal type is received. It might seem like the signal receiving happens in the background, but it doesn't. At the lowest level signals are received using computer.pullSignal, which waits for any kind of signal and returns it. The event library builds on top of that - event.pull calls computer.pullSignal multiple times until the desired signal is received, and also calls any registered signal listeners for all received signals, and runs timers when they are due. No background process "magic" going on there. :)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.