Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > stupid TCP

Reply
Thread Tools

stupid TCP

 
 
Joe Van Dyk
Guest
Posts: n/a
 
      06-30-2005
require 'socket'

tcp_server =3D TCPServer.new 'localhost', 4321

puts "connecting..."
tcp_client =3D TCPSocket.new 'localhost', 4321
tcp_client.write "Hello World"
puts "finshed writing"

session =3D tcp_server.accept
puts "we recieved: <#{session.gets}>"



Why doesn't that work?


 
Reply With Quote
 
 
 
 
Joe Van Dyk
Guest
Posts: n/a
 
      06-30-2005
On 6/30/05, Joe Van Dyk <(E-Mail Removed)> wrote:
> require 'socket'
>=20
> tcp_server =3D TCPServer.new 'localhost', 4321
>=20
> puts "connecting..."
> tcp_client =3D TCPSocket.new 'localhost', 4321
> tcp_client.write "Hello World"
> puts "finshed writing"
>=20
> session =3D tcp_server.accept
> puts "we recieved: <#{session.gets}>"
>=20
>=20
>=20
> Why doesn't that work?


Or, a threaded version:

require 'socket'

t =3D Thread.new do=20
tcp_server =3D TCPServer.new 'localhost', 4321
while (session =3D tcp_server.accept)
puts "we recieved: <#{session.gets}>"
end
end

tcp_client =3D TCPSocket.new 'localhost', 4321
tcp_client.write "Hello World"

t.join

Still doesn't work though. What am I missing?


 
Reply With Quote
 
 
 
 
Joe Van Dyk
Guest
Posts: n/a
 
      06-30-2005
On 6/30/05, Joe Van Dyk <(E-Mail Removed)> wrote:
> On 6/30/05, Joe Van Dyk <(E-Mail Removed)> wrote:
> > require 'socket'
> >
> > tcp_server =3D TCPServer.new 'localhost', 4321
> >
> > puts "connecting..."
> > tcp_client =3D TCPSocket.new 'localhost', 4321
> > tcp_client.write "Hello World"
> > puts "finshed writing"
> >
> > session =3D tcp_server.accept
> > puts "we recieved: <#{session.gets}>"
> >
> >
> >
> > Why doesn't that work?

>=20
> Or, a threaded version:
>=20
> require 'socket'
>=20
> t =3D Thread.new do
> tcp_server =3D TCPServer.new 'localhost', 4321
> while (session =3D tcp_server.accept)
> puts "we recieved: <#{session.gets}>"
> end
> end
>=20
> tcp_client =3D TCPSocket.new 'localhost', 4321
> tcp_client.write "Hello World"
>=20
> t.join
>=20
> Still doesn't work though. What am I missing?


Aha. I'm guessing it has something to do with not sending the data
immediately. If I do

tcp_client.close

Then the data gets sent. But I don't want to close the socket. And
I'm not seeing anything (yet) that would let me immediately send (I
tried IO#flush) the data over the socket.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stupid question...waiting for a stupid answer Brandon McCombs Java 4 08-28-2006 06:57 PM
Stupid question. Please, only stupid responders. If you're not sureif you're stupid, you probably aren't. =?ISO-8859-1?Q?R=F4g=EAr?= Computer Support 6 07-18-2005 05:11 AM
stupid stupid stupid kpg MCSE 17 11-26-2004 02:59 PM
stupid test questions and stupid awnsers in Measureup 70-320 test john MCAD 0 10-13-2004 11:43 PM
Stupid is as Stupid Does! Michael P Gabriel Digital Photography 3 06-26-2004 12:49 PM



Advertisments