Project

General

Profile

Bug #11374 » clientForkTk1.rb

tmbartaw (Tarek Bartaw), 07/18/2015 08:11 PM

 
require 'tk'
require 'tkextlib/tile'
require 'socket' # Sockets are in standard library
require 'thread'
require 'fiber'


$hostname = '192.168.1.122'
$port = 2000
$s = TCPSocket.open($hostname, $port)







root = TkRoot.new
$something = 'a'
# $s = TCPSocket.open($hostname, $port)

#while $something != 'bye' do

#frame
frame = Tk::Tile::Frame.new(root).grid
frame['padding'] = '5 10'
frame['borderwidth'] = 5
frame['relief'] = 'raised'
#Entry
$servername = TkVariable.new
entryname = Tk::Tile::Entry.new(frame) { textvariable $servername }
entryname.insert(0, 'Enter Server Name') # insert new text at a given index

#labels
lblDefence = Tk::Tile::Label.new(frame) {text 'DEFENCE'}
lblRefresh = Tk::Tile::Label.new(frame) {text 'REFRESH'}
lblHistoric = Tk::Tile::Label.new(frame) {text 'Historic'}
lblFb1 = Tk::Tile::Label.new(frame) {text 'fb1'}
lblFb2 = Tk::Tile::Label.new(frame) {text 'fb2'}
lblFb3 = Tk::Tile::Label.new(frame) {text 'fb3'}
lblTh1 = Tk::Tile::Label.new(frame) {text 'th1'}
lblTh2 = Tk::Tile::Label.new(frame) {text 'th1'}
# Grid all the widgets
entryname.grid :column => 0, :row => 0
lblDefence.grid :column => 0, :row => 1
lblRefresh.grid :column => 0, :row => 5
lblHistoric.grid :column => 0, :row => 8
lblFb1.grid :column => 1, :row => 1
lblFb2.grid :column => 2, :row => 1
lblFb3.grid :column => 3, :row => 1
lblTh1.grid :column => 1, :row => 5
lblTh2.grid :column => 2, :row => 5


#Tk.restart()
Thread.start{Tk.mainloop}
=begin
#$s = TCPSocket.open(hostname, port)
#loop {
while line = $s.gets # Read lines from the socket
Thread.new{ puts line.chop} # And print with platform line terminator
end
# }
=end
while (session = server.accept)
Thread.new{MainServer.handle_connection(session)}
end




(1-1/5)