School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,431 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,503 people online right now. Registration is fast and FREE... Join Now!




socket.Send() function

 

socket.Send() function, sending data using a socket

chris772

25 May, 2009 - 09:44 AM
Post #1

D.I.C Head
**

Joined: 13 Mar, 2009
Posts: 166



Thanked: 2 times
My Contributions
I am a novice to Ruby, but I have the language figured out almost. The one thing I have problems with (in any language) is sockets. How is data sent to the server in Ruby? I figured out you need to use the Send() function, but what are the parameters? Do you need to use a UDP socket to use the function or is TCP accepted?

At the moment, this is the only code I can find:
CODE

socket.send([Time.now.to_i].pack("N"), 0, host, port)


User is offlineProfile CardPM
+Quote Post


JackOfAllTrades

RE: Socket.Send() Function

26 May, 2009 - 06:07 AM
Post #2

I exist to Google your problems.
Group Icon

Joined: 23 Aug, 2008
Posts: 4,948



Thanked: 424 times
Dream Kudos: 50
Expert In: Being annoyed with lazy people.

My Contributions
Whether to use UDP or TCP depends entirely on the server.

At its heart, like everything Unix-related, a socket is a file. Therefore, you can use regular IO functions to write to/read from the socket.
User is offlineProfile CardPM
+Quote Post

chris772

RE: Socket.Send() Function

26 May, 2009 - 05:00 PM
Post #3

D.I.C Head
**

Joined: 13 Mar, 2009
Posts: 166



Thanked: 2 times
My Contributions
Thank you. I just used ".syswrite".

CODE

require 'socket'

host = 'vortex.labs.pulltheplug.org'
port = 5842

socket = TCPSocket.open(host,port)

send = socket.syswrite("1")
response = socket.read
print response


This post has been edited by chris772: 26 May, 2009 - 05:01 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 12:43AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month