# Chat server telnet client problem

**URL:** <https://www.ruby-forum.com/t/chat-server-telnet-client-problem/108594>\
**Category:** Ruby\
**Created:** [July 5, 2007, 6:56am UTC](https://www.ruby-forum.com/t/chat-server-telnet-client-problem/108594 "2007-07-05T06:56:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgirdhar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/bc8723/32.png) [@dgirdhar](https://www.ruby-forum.com/u/dgirdhar)\
**Post date:** [July 5, 2007, 6:56am UTC](https://www.ruby-forum.com/t/chat-server-telnet-client-problem/108594/1 "2007-07-05T06:56:23Z")

</div>

Hi,  
I copied chat server code from one or Ruby site.  
Following code is working fine But I am facing very small problem, when  
i am launching any client using telnet, then I am not able to see what I  
am typing on client console.  
example :

> telnet localhost 7666

Please help me to find out the problem.

Regards:  
Dhiraj

require ‘socket’  
class ChatServer

def initialize(port) #Instantiating the server  
@sockets\_in = Array.new  
@serv\_sock = TCPServer.new("",port)  
@serv\_sock.setsockopt(Socket::SOL\_SOCKET, Socket::SO\_REUSEADDR, 1)  
puts “Chat server started on port #{port}.”  
@sockets\_in.push(@serv\_sock)  
end

def run # The runtime code for the server  
while true  
someone\_there = select(@sockets\_in, nil, nil, nil)  
if someone\_there != nil #Someone IS there, maybe wanting to  
talk?  
for socket in someone\_there[0] #Check the sockets array  
#Do we have a connect,…  
if socket == @serv\_sock then  
accept\_new  
else  
#…or did they leave,…  
if socket.eof? then #If it sends an end of file notice

- client disconnected.  
str = “Client left  
#{socket.peeraddr[2]}:#{socket.peeraddr[1]}.”  
broadcast\_string(str,socket)  
socket.close  
@sockets\_in.delete(socket)  
else  
#…or are they talking?  
str = “#{socket.peeraddr[2]}:#{socket.peeraddr[1]}  
says: #{socket.gets}”  
broadcast\_string(str,socket)  
end  
end  
end  
end  
end  
end

end

myChat = ChatServer.new(7680)  
myChat.run
