Ruby and C network interaction

C

cilphex

Hi,

I'm working on a small client/server application in my spare time,
using C and win32 for the client and Ruby for the server. I'm having
an interaction issue and was wondering if anyone could help. I'm not
an expert in Ruby or networking :\

Anyway, on the client side I set up a socket and connect to the server,
then send a username with:

send (socket, myMessage, sizeof (myMessage))

Which works fine. The Ruby server receives and prints it with:

username = session.recv(20).strip
puts "Username: '#{username}'"

(session is an instance of TCPServer)

A password is sent the same way. My trouble occurs when I try to send
data back to the client from the server.

The client tries to receive with:

recv (socket, sockMsg, sizeof(sockMsg), 0);

And the server sends with:

sent = session.send("success", 0)
puts "#{sent} characters sent"

The server outputs "7 characters sent", but I don't receive anything on
the client side. I output the contents of sockMsg, and it's empty.

Server code is here (It's not much, just something simple):
http://www.craighammell.com/code/server.rb

Any help would be appreciated.

Thanks.
 
A

ara.t.howard

Hi,

I'm working on a small client/server application in my spare time,
using C and win32 for the client and Ruby for the server. I'm having
an interaction issue and was wondering if anyone could help. I'm not
an expert in Ruby or networking :\

Anyway, on the client side I set up a socket and connect to the server,
then send a username with:

send (socket, myMessage, sizeof (myMessage))

Which works fine. The Ruby server receives and prints it with:

username = session.recv(20).strip
puts "Username: '#{username}'"

(session is an instance of TCPServer)

A password is sent the same way. My trouble occurs when I try to send
data back to the client from the server.

The client tries to receive with:

recv (socket, sockMsg, sizeof(sockMsg), 0);

And the server sends with:

sent = session.send("success", 0)
puts "#{sent} characters sent"

The server outputs "7 characters sent", but I don't receive anything on
the client side. I output the contents of sockMsg, and it's empty.

Server code is here (It's not much, just something simple):
http://www.craighammell.com/code/server.rb

Any help would be appreciated.

buffering.

try

socket.sync = true

cheers.

-a
--
===============================================================================
| ara [dot] t [dot] howard [at] noaa [dot] gov
| all happiness comes from the desire for others to be happy. all misery
| comes from the desire for oneself to be happy.
| -- bodhicaryavatara
===============================================================================
 
C

cilphex

Ah, I had an error in my C code! Sorry for wasting your time everyone.
I thought it was good so I figured it had to be the Ruby.

Thanks for your help, though, and validating that the server worked.

Craig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,787
Messages
2,569,632
Members
45,340
Latest member
Thalia56P0

Latest Threads

Top