Forum: Ruby Ruby and C network interaction

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E677a583236141e5096e7d3f2d5feb01?d=identicon&s=25 cilphex (Guest)
on 2005-11-30 04:53
(Received via mailing list)
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.
Cb48ca5059faf7409a5ab3745a964696?d=identicon&s=25 ara.t.howard (Guest)
on 2005-11-30 05:13
(Received via mailing list)
On Wed, 30 Nov 2005, cilphex wrote:

> send (socket, myMessage, sizeof (myMessage))
>
> 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
E677a583236141e5096e7d3f2d5feb01?d=identicon&s=25 cilphex (Guest)
on 2005-11-30 06:38
(Received via mailing list)
Just tried this, it didn't help :\

Thanks
47b1910084592eb77a032bc7d8d1a84e?d=identicon&s=25 vjoel (Guest)
on 2005-11-30 06:58
(Received via mailing list)
cilphex wrote:
> Just tried this, it didn't help :\
>
> Thanks
>

I tried your server against a ruby client and it worked. Ruby 1.8.2,
WinXP.
E677a583236141e5096e7d3f2d5feb01?d=identicon&s=25 cilphex (Guest)
on 2005-11-30 07:35
(Received via mailing list)
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
This topic is locked and can not be replied to.