
Security News
Astral Launches pyx: A Python-Native Package Registry
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
A basic select multiplexing based TCP server. Client connections are handled by a method handler or a block handler. The basic format for handlers is:
def handler(server, client_socket)
end
server = Cwgem::SelectServer.new("localhost", 3555)
server.setup_method_handler(method(:handler))
server.start
Where server is the server object itself, and client socket is the socket of the client. The server is passed in so you can do things like shutding down the server based on a client command:
def handler(server,client_socket)
command = client_socket.gets
server.shutdown if command.chomp! == "exit"
end
server = Cwgem::SelectServer.new("localhost", 3555)
server.setup_method_handler(method(:handler))
server.start
Blocks can also be used as client connection handlers:
server = Cwgem::SelectServer.new("localhost", 3555)
server.start do | server, client_socket |
end
Note that either a method handler must be setup before calling server.start, or a block passed into it. Failure to do so will result in an ArgumentError:
server = Cwgem::SelectServer.new("localhost", 3555)
server.start # this will throw ArgumentError since no handler is setup
If you need to carry around extra metadata for client connections, the best method is to override the accept method and extend the socket through a module. In this example the client socket has a username attribute added to it by extending a ChatClient module.
module ChatClient
attr_accessor :username
end
server = Cwgem::SelectServer.new("localhost", 3555)
def server.accept
client = self.accept
client.extend(ChatClient)
@sockets << client
end
server.start do | server, socket |
1
end
This example is an embedded ruby script that can be run using ruby -x Readme.markdown
. It binds to localhost on port 3555, and acts as a simple echo server. The simple server can be shutdown by sending the USR1 signal kill -USR1 [processid]
.
#! ruby
require 'cwgem-selectserver'
server = Cwgem::SelectServer.new("localhost", 3555)
Signal.trap("USR1") { server.shutdown; server.shutdown_handler; exit }
server.start do | server, socket |
data = socket.gets
socket.write data
end
__END__
FAQs
Unknown package
We found that cwgem-selectserver demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.