Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # IRC Write Program
- # Written by Bryan Miller
- # get sockets from standard library
- require 'socket'
- # get SSL sockets from standard library
- require 'openssl'
- # get timeout from library to leave input and check for ping
- require 'timeout'
- # get hostname to connect to from the user
- print "hostname: "
- hostname = gets.chomp
- # for SSL port is always 6697
- port = 6697
- # open the socket by connecting to the hostname and port
- s = TCPSocket.open(hostname, port)
- ssl_context = OpenSSL::SSL::SSLContext.new()
- ssl_context.ssl_version = :SSLv23
- ssl_socket = OpenSSL::SSL::SSLSocket.new(s, ssl_context)
- ssl_socket.sync_close = true
- ssl_socket.connect
- # send nickname to the server
- ssl_socket.puts "NICK ubuntu76\r\n"
- # send user info to the server
- ssl_socket.puts "USER unbuntu76 8 * :linux\r\n"
- # send registration info to the server to identify your registered nick
- ssl_socket.puts "NICKSERV identify (enter your password here)\r\n"
- # get channel to join from the user and join the channel
- print "Enter channel to join: "
- channel = gets.chomp
- ssl_socket.puts "JOIN #" + channel
- puts "Enter text to send to channel: "
- while (1)
- begin
- input = ""
- Timeout::timeout(240) do
- ssl_socket.puts "PONG :Linux Rocks !!"
- puts "PONG :Linux Rocks !!"
- input = gets.chomp
- end
- ssl_socket.puts "PRIVMSG #" + channel + " :" + input
- rescue Timeout::Error
- end
- end
- # close socket when done
- ssl_socket.close
Advertisement
Add Comment
Please, Sign In to add comment