Re: help need in chat client/server



[Note: parts of this message were removed to make it a legal post.]

On Mon, Apr 14, 2008 at 11:25 AM, HadsS <a.hadss@xxxxxxxxx> wrote:

Hey...
Im new to this network programmin and I need help with this code i
copied and changed a little.
this is a client/server chat..
-----------------------
Server code:

require "socket"
PORT = 12321
server = TCPServer.new(PORT)
flag=true
while (session = server.accept)
while flag==true
print "Sending:"
line=gets.chomp!
session.puts line
end
end
----------------

Client Code:
require "socket"

PORT = 12321
HOST = ARGV[0] || "localhost"
flag=true
session = TCPSocket.new(HOST, PORT)
while flag==true
line = session.gets
puts "Recived:#{line} "
end
---------

i dont know what i did but its sort of doing a one way communication..
can someone please help me with creating two clients and making them
chat 2way amongst them..
please.. i would really be thankfulll
waiting for a reply


There are a few logical/structural problems here:

Firstly, it is only one way because one end is sending and the other
listening but the sending end never listens and the listening end never
sends.

Secondly, control in this is going to be painful as it is. You probably
want to thread your program so that each end can "talk" and "listen" at the
same time. You could make it clunky and just switch between the two but
that would be rather un-intuative.

I would offer up some sample code but haven't done any socket programming in
Ruby and am currently at work I bet someone will come along with more
useful info though (I offer this as something to get you going in the right
direction until then).

--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

.



Relevant Pages

  • socket connection problem between C++ ActiveX and C# listening port
    ... I don't know if there is discrepancy between straight C code socket ... Few years ago I wrote an ATL ActiveX and a C++ daemon running locally ... The daemon opens a port on "localhost" and listens ... and send messages to the listening daemon. ...
    (microsoft.public.pocketpc.developer)
  • Re: Socket and cycle problem
    ... listening this port countinously. ... So I need make some loop to print data from 3883 port permanent. ... the data it receives from each connection after the remote side drops ... If you were to use the socket module, then it would look something like this: ...
    (comp.lang.python)
  • Re: BBC TV 4 - Hawkwind: Do not panic
    ... Server processes actively have to tell the OS they want to listen to the network on port such-and-such. ... (i.e., not the normal server listening on socket 80), and you set up the ... Telnet server to listen on socket 80, surely it should all `just work' ...
    (uk.comp.sys.mac)
  • Re: Socket programming question.
    ... it assigns a new port number and provides the connecting ip address, ... the listen could be on port 80, but the link is random and could be on port ... I am new to socket programming and I have been searching on ... that controls the starting and stopping of listening to a socket. ...
    (microsoft.public.win32.programmer.networks)