Daytime
- Posted by irv mullins <irvm at ellijay.com> Apr 23, 2004
- 506 views
Here's a short program to connect to the daytime service and return the current time: (also, let's see if syntax coloring works)
include gtk2/wrapper.e include socketlib.eu as sock atom win, panel, input, lbl, btn ----------------------------------- function GetTime() ----------------------------------- object host, service, socket, result set(lbl,"Text","") host = sock:GetHostbyName(get(input,"Text")) if atom(host) then Error(win,"Sorry","Cannot locate host") else set(lbl,"Text",host[sock:ADDR]) service = sock:GetServbyName("daytime","tcp") if atom(service) then Error(win,"Sorry","Service not available!") else set(lbl,"Text",sprintf("Service: %s\nPort: %d\nProtocol: %s",service)) socket = sock:Connect(host[sock:NODE],service[sock:PORT]) if socket = -1 then Error(win,"Sorry","Cannot connect to service!") else result = sock:ReadAndWait(socket) Info(win,"Results",result) end if end if end if return NULL end function constant gettime = call_back(routine_id("GetTime")) --------------------[ MAIN ]---------------------- win = window("Daytime") set(win,"Size",{200,200}) set(win,"Border",10) panel = vbox(0,0) addto(win,panel) input = entry() set(input,"Text","localhost") pack(panel,input,0,0,0) lbl = label("Click the button below\nto connect to Daytime Service\non localhost") addto(panel,lbl) btn = button("gtk-ok") when(btn,"clicked",gettime,0) pack(panel,-btn,0,0,0) show(win) main()