# Help with socket method in rails controller

**URL:** <https://www.ruby-forum.com/t/help-with-socket-method-in-rails-controller/97984>\
**Category:** Ruby\
**Created:** [July 11, 2006, 9:17pm UTC](https://www.ruby-forum.com/t/help-with-socket-method-in-rails-controller/97984 "2006-07-11T21:17:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 11, 2006, 9:17pm UTC](https://www.ruby-forum.com/t/help-with-socket-method-in-rails-controller/97984/1 "2006-07-11T21:17:33Z")

</div>

I’m trying to write a method in a controller to write to a socket, I’m  
kinda stumped right now.  
Here’s my code:  
def socketwriter  
require “socket”  
s=TCPSocket.new(“ip”,“port”)  
s.write (“arguments|I|want|to|send|”)  
end

so if I just write this as a ruby script and code in the ip, port,  
arguments, etc. it works great. I’m trying to figure out how to post to

this method in rails. I have a database that contains all the  
information I need for the socket parameters and the commands to send,  
I just need a little help on how to post them to the controller.

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 12, 2006, 8:10am UTC](https://www.ruby-forum.com/t/help-with-socket-method-in-rails-controller/97984/2 "2006-07-12T08:10:37Z")

</div>

Post parameters in Rails are stored in the params hash (accessible from  
the controller). Create an action, get your data from the params hash  
then use the socket in the normal way.
