File: u_tabpg_udp_listen.sru
Size: 9758
Date: Mon, 31 Dec 2018 21:14:39 +0100
$PBExportHeader$u_tabpg_udp_listen.sru
$PBExportComments$Base tabpage object
forward
global type u_tabpg_udp_listen from u_tabpg
end type
type cb_listenblob from commandbutton within u_tabpg_udp_listen
end type
type cb_stop from commandbutton within u_tabpg_udp_listen
end type
type cb_listen from commandbutton within u_tabpg_udp_listen
end type
type sle_port from singlelineedit within u_tabpg_udp_listen
end type
type st_3 from statictext within u_tabpg_udp_listen
end type
type cb_reset from commandbutton within u_tabpg_udp_listen
end type
type lb_msgs from listbox within u_tabpg_udp_listen
end type
type st_2 from statictext within u_tabpg_udp_listen
end type
end forward

global type u_tabpg_udp_listen from u_tabpg
string text = "UDP Listen"
event ue_notifymsg pbm_custom01
event ue_notifystop pbm_custom02
cb_listenblob cb_listenblob
cb_stop cb_stop
cb_listen cb_listen
sle_port sle_port
st_3 st_3
cb_reset cb_reset
lb_msgs lb_msgs
st_2 st_2
end type
global u_tabpg_udp_listen u_tabpg_udp_listen

type variables
n_sharedobj in_shr

end variables

forward prototypes
public function errorreturn of_sharedobjecterrors (errorreturn aer_result)
public subroutine of_setrunning (boolean ab_isrunning)
public subroutine of_addmsg (string as_msg)
end prototypes

event ue_notifymsg;// receive a message

String ls_msg, ls_from

If wparam = 0 Then Return

ls_msg = String(wparam, "address")

If lparam > 0 Then
   ls_from = String(lparam, "address")
   of_AddMsg("Message from: " + ls_from)
   of_AddMsg("Msg Received: " + ls_msg)
Else
   of_AddMsg(ls_msg)
End If

end event

event ue_notifystop;// receive a stop message

String ls_msg

// display the message
If wparam > 0 Then
   ls_msg = String(wparam, "address")
   of_AddMsg(ls_msg)
End If

// enable controls
of_SetRunning(False)

// unregister the shared object
SetNull(in_shr)
SharedObjectUnregister("background")
Destroy in_shr

end event

public function errorreturn of_sharedobjecterrors (errorreturn aer_result);// display error messages for SharedObject functions
choose case aer_result
   case SharedObjectExistsError!
      MessageBox("SharedObjectRegister Error", &
            "The instance name has already been used!", &
            StopSign!)
   case SharedObjectCreatePBSessionError!
      MessageBox("SharedObjectRegister Error", &
            "The shared object session could not be created!", &
            StopSign!)
   case SharedObjectCreateInstanceError!
      MessageBox("SharedObjectGet Error", &
            "The local reference to the shared object could " + &
            "not be created!", StopSign!)
   case SharedObjectNotExistsError!
      MessageBox("SharedObjectGet Error", &
            "The instance name has not been registered!", &
            StopSign!)
end choose
Return aer_result

end function

public subroutine of_setrunning (boolean ab_isrunning);// enable/disable buttons
cb_listen.Enabled = Not ab_isrunning
cb_listenblob.Enabled = Not ab_isrunning
cb_stop.Enabled = ab_isrunning
gb_Listening = ab_isrunning

end subroutine

public subroutine of_addmsg (string as_msg);Integer li_item

li_item = lb_msgs.AddItem(as_msg)
lb_msgs.SelectItem(li_item)

end subroutine

on u_tabpg_udp_listen.create
int iCurrent
call super::create
this.cb_listenblob=create cb_listenblob
this.cb_stop=create cb_stop
this.cb_listen=create cb_listen
this.sle_port=create sle_port
this.st_3=create st_3
this.cb_reset=create cb_reset
this.lb_msgs=create lb_msgs
this.st_2=create st_2
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.cb_listenblob
this.Control[iCurrent+2]=this.cb_stop
this.Control[iCurrent+3]=this.cb_listen
this.Control[iCurrent+4]=this.sle_port
this.Control[iCurrent+5]=this.st_3
this.Control[iCurrent+6]=this.cb_reset
this.Control[iCurrent+7]=this.lb_msgs
this.Control[iCurrent+8]=this.st_2
end on

on u_tabpg_udp_listen.destroy
call super::destroy
destroy(this.cb_listenblob)
destroy(this.cb_stop)
destroy(this.cb_listen)
destroy(this.sle_port)
destroy(this.st_3)
destroy(this.cb_reset)
destroy(this.lb_msgs)
destroy(this.st_2)
end on

event ue_pagechanged;call super::ue_pagechanged;sle_port.SetFocus()

end event

event destructor;call super::destructor;of_setreg("udp_listen_port", sle_port.text)

end event

event ue_postopen;call super::ue_postopen;sle_port.text = of_getreg("udp_listen_port", "")

end event

type cb_listenblob from commandbutton within u_tabpg_udp_listen
integer x = 37
integer y = 416
integer width = 480
integer height = 100
integer taborder = 30
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Listen for a Blob"
end type

event clicked;ErrorReturn ler_result
UInt lui_port

SetPointer(HourGlass!)

lui_port = Long(sle_port.text)
If lui_port = 0 Then
   sle_port.SetFocus()
   MessageBox("Edit Error", "Server Port is required!")
   Return
End If

// register the shared object
ler_result = SharedObjectRegister("n_sharedobj", "background")
If of_SharedObjectErrors(ler_result) = Success! Then
   // get a reference to the shared object
   ler_result = SharedObjectGet("background", in_shr)
   If of_SharedObjectErrors(ler_result) = Success! Then
      // enable/disable buttons
      of_SetRunning(True)
      of_AddMsg("Listening...")
      // call functions in the shared object
      in_shr.of_RegisterEvents(Handle(Parent), 1, 2)
      in_shr.Post of_RecvFromBlob(lui_port, gi_ipversion)
   End If
End If

end event

type cb_stop from commandbutton within u_tabpg_udp_listen
integer x = 37
integer y = 576
integer width = 480
integer height = 100
integer taborder = 40
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
boolean enabled = false
string text = "Stop Listening"
end type

event clicked;Long ll_last
UInt lui_port
String ls_hostname, ls_message

lui_port = Long(sle_port.text)
If lui_port = 0 Then
   sle_port.SetFocus()
   MessageBox("Edit Error", "Server Port is required!")
   Return
End If

// send stop message to self
ls_hostname = gn_ws.of_GetHostName()
gn_ws.of_SendTo(ls_hostname, lui_port, "stop")
of_AddMsg("Stopping...")

end event

type cb_listen from commandbutton within u_tabpg_udp_listen
integer x = 37
integer y = 256
integer width = 480
integer height = 100
integer taborder = 20
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Listen for a String"
end type

event clicked;ErrorReturn ler_result
UInt lui_port

SetPointer(HourGlass!)

lui_port = Long(sle_port.text)
If lui_port = 0 Then
   sle_port.SetFocus()
   MessageBox("Edit Error", "Server Port is required!")
   Return
End If

// register the shared object
ler_result = SharedObjectRegister("n_sharedobj", "background")
If of_SharedObjectErrors(ler_result) = Success! Then
   // get a reference to the shared object
   ler_result = SharedObjectGet("background", in_shr)
   If of_SharedObjectErrors(ler_result) = Success! Then
      // enable/disable buttons
      of_SetRunning(True)
      of_AddMsg("Listening...")
      // call functions in the shared object
      in_shr.of_RegisterEvents(Handle(Parent), 1, 2)
      in_shr.of_SetUnicode(w_main.cbx_setunicode.checked)
      in_shr.Post of_RecvFromString(lui_port, gi_ipversion)
   End If
End If

end event

type sle_port from singlelineedit within u_tabpg_udp_listen
integer x = 219
integer y = 96
integer width = 224
integer height = 80
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
integer limit = 5
borderstyle borderstyle = stylelowered!
end type

type st_3 from statictext within u_tabpg_udp_listen
integer x = 37
integer y = 108
integer width = 142
integer height = 60
integer textsize = -8
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Port:"
boolean focusrectangle = false
end type

type cb_reset from commandbutton within u_tabpg_udp_listen
integer x = 951
integer y = 1248
integer width = 334
integer height = 100
integer taborder = 50
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Reset Msgs"
end type

event clicked;lb_msgs.Reset()

end event

type lb_msgs from listbox within u_tabpg_udp_listen
integer x = 1353
integer y = 96
integer width = 1541
integer height = 1252
integer taborder = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
boolean hscrollbar = true
boolean vscrollbar = true
boolean sorted = false
borderstyle borderstyle = stylelowered!
end type

type st_2 from statictext within u_tabpg_udp_listen
integer x = 1353
integer y = 32
integer width = 283
integer height = 60
integer textsize = -8
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Messages:"
boolean focusrectangle = false
end type