# Simple socketing

**URL:** <https://www.ruby-forum.com/t/simple-socketing/98187>\
**Category:** Ruby\
**Created:** [July 12, 2006, 11:31pm UTC](https://www.ruby-forum.com/t/simple-socketing/98187 "2006-07-12T23:31:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![canute](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ba0ec/32.png) [@canute](https://www.ruby-forum.com/u/canute)\
**Post date:** [July 12, 2006, 11:31pm UTC](https://www.ruby-forum.com/t/simple-socketing/98187/1 "2006-07-12T23:31:51Z")

</div>

Hi there, I recently started with Ruby and I am trying to make a very  
simple irc bot, but I am having some slight problems though.

This is what I came up with:

require ‘socket’  
class Irc  
def connect(server, port = 6667)  
@socket = TCPsocket.new(server, port)  
end  
def to\_server(text)  
@socket.gets(text)  
return true  
end  
def from\_server()  
return @socket.puts  
end  
end  
irc = Irc.new  
irc.connect(“irc.homelien.no”, 6667)  
irc.to\_server(‘NICK: testbot’)  
irc.to\_server(‘USER: testbot “” “[irc.efnet.net](http://irc.efnet.net)” :testbot’)  
go = true  
while go == true  
if (text = irc.from\_server)  
puts(text)  
end  
end

Doesn’t work though, I just get the loop.

---

<div class="post-metadata">

**Author:** ![canute](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7ba0ec/32.png) [@canute](https://www.ruby-forum.com/u/canute)\
**Post date:** [July 12, 2006, 11:52pm UTC](https://www.ruby-forum.com/t/simple-socketing/98187/2 "2006-07-12T23:52:19Z")

</div>

> def to\_server(text)  
> @socket.gets(text)  
> return true  
> end  
> def from\_server()  
> return @socket.puts  
> end

You’ve got gets and puts the wrong way around. Read them as Get String  
and Put String, gets reads from the socket and puts writes to it.

Also, there’s a protocol error there, you want to\_server to read like  
this:

def to\_server(text)  
@socket.puts(text.to\_s+"\r\n") # The line breaks are important, must  
be CRLF.  
end
