Class: LocalMessageClient
- Inherits:
-
Object
- Object
- LocalMessageClient
- Defined in:
- lib/local_message/local_message_client.rb
Instance Attribute Summary collapse
-
#listen_port ⇒ Object
readonly
Returns the value of attribute listen_port.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(server_hostname, server_port, user_name) ⇒ LocalMessageClient
constructor
A new instance of LocalMessageClient.
- #listen ⇒ Object
- #register ⇒ Object
- #send_message(message) ⇒ Object
Constructor Details
#initialize(server_hostname, server_port, user_name) ⇒ LocalMessageClient
7 8 9 10 11 12 |
# File 'lib/local_message/local_message_client.rb', line 7 def initialize(server_hostname, server_port, user_name) @server = server_hostname @port = server_port @username = user_name @listen_port = Random.rand(2000..30_000) end |
Instance Attribute Details
#listen_port ⇒ Object (readonly)
Returns the value of attribute listen_port.
5 6 7 |
# File 'lib/local_message/local_message_client.rb', line 5 def listen_port @listen_port end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/local_message/local_message_client.rb', line 5 def port @port end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
5 6 7 |
# File 'lib/local_message/local_message_client.rb', line 5 def server @server end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
5 6 7 |
# File 'lib/local_message/local_message_client.rb', line 5 def username @username end |
Instance Method Details
#listen ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/local_message/local_message_client.rb', line 24 def listen server = TCPServer.open(listen_port) client = server.accept = client.read client.close server.close end |
#register ⇒ Object
14 15 16 |
# File 'lib/local_message/local_message_client.rb', line 14 def register ("@register #{username} #{listen_port}") end |
#send_message(message) ⇒ Object
18 19 20 21 22 |
# File 'lib/local_message/local_message_client.rb', line 18 def () socket = TCPSocket.open(server, port) socket.write() socket.close end |