From: Matthew PATTISON Date: 2002-03-26T23:39:58+09:00 Subject: Problems with sockets: connecting a bot to Unreal Tournament Hi, I'm trying to create a bot (computer controlled character) for Unreal Tournament which needs to connect to the game via a socket interface. I haven't used sockets before and I'm running into some problems. I have some tcl example code which does what I want, but the equivalent code in Ruby (as I write it) doesn't seem to work: tcl: set s [socket "localhost" 3000] gets $s line puts stdout $line set line "init \{name TclBot\} \{team 255\}" puts $s $line flush $s puts stdout $line gets $s line puts stdout $line this outputs: NFO {Gametype BotDomination} {Level DOM-Stalwart} {GoalTeamScore 100.000000} {Ti meLimit 0} {MaxTeams 2} {MaxTeamSize 16} init {name TclBot} {team 255} VMS {String Yigal entered the game.} which is what I want. in Ruby (1.6.6 single step installer in Windows 2000) require 'socket' s = TCPSocket.new('localhost', 3000) data = s.recv(150) #data = s.gets puts data str = 'init {name RubyBot} {team 255}' s.send(str,Socket:MSG_OOB) #I've also tried Socket::MSG_DONTROUTE and 0 s.flush puts str if select([s],nil, nil, 10) != nil data = s.recv(150) #data = s.gets puts data end this outputs: NFO {Gametype BotDomination} {Level DOM-Stalwart} {GoalTeamScore 100.000000} {Ti meLimit 0} {MaxTeams 2} {MaxTeamSize 16} init {name RubyBot} {team 255} which is missing the last line, which is the reply from Unreal Tournament acknowledging the bot has joined the game. Without the if select() != nil around the last recv() call, the ruby script hangs. Also the tcl script runs almost instantaneously, the ruby script takes a good 20 seconds to not work properly. I assume there is something stupid I'm doing wrong, please enlighten me. Also, in tcl I have: fconfigure $s -blocking 0 fileevent $s readable [list Reader $s] which makes the socket non-blocking and then sets up a callback for the socket. How do I do this in ruby? Thanks a lot if someone can help me out. Matt