Skip to content

Instantly share code, notes, and snippets.

@znz
Last active Apr 6, 2018
Embed
What would you like to do?
JIS (IRCnet) <-> UTF-8 (IRC client) proxy
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'nkf'
require 'socket'
Socket.tcp_server_loop(6668) do |socket, client_addr|
begin
begin
ircnet_socket = Socket.tcp('irc.ircnet.ne.jp', 6667)
loop do
rs, = IO.select([socket, ircnet_socket])
break if rs.empty?
if rs.include?(ircnet_socket)
jis_line = ircnet_socket.gets
socket.puts NKF.nkf('-Jwxm0 --fb-xml', jis_line)
end
if rs.include?(socket)
utf8_line = socket.gets
ircnet_socket.puts NKF.nkf('-Wjxm0 --fb-xml', utf8_line)
end
end
rescue
p $!
ensure
ircnet_socket.close if ircnet_socket && !ircnet_socket.closed?
end
ensure
socket.close if !socket.closed?
end
end
@znz

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment