File: u_tabpg_udp_send.sru
Size: 11113
Date: Mon, 31 Dec 2018 21:14:39 +0100
$PBExportHeader$u_tabpg_udp_send.sru
$PBExportComments$Base tabpage object
forward
global type u_tabpg_udp_send from u_tabpg
end type
type cb_sendblob from commandbutton within u_tabpg_udp_send
end type
type sle_message from singlelineedit within u_tabpg_udp_send
end type
type st_3 from statictext within u_tabpg_udp_send
end type
type cb_send from commandbutton within u_tabpg_udp_send
end type
type cb_reset from commandbutton within u_tabpg_udp_send
end type
type lb_msgs from listbox within u_tabpg_udp_send
end type
type st_4 from statictext within u_tabpg_udp_send
end type
type sle_hostname from singlelineedit within u_tabpg_udp_send
end type
type st_1 from statictext within u_tabpg_udp_send
end type
type st_2 from statictext within u_tabpg_udp_send
end type
type sle_port from singlelineedit within u_tabpg_udp_send
end type
end forward

global type u_tabpg_udp_send from u_tabpg
string text = "UDP Send"
cb_sendblob cb_sendblob
sle_message sle_message
st_3 st_3
cb_send cb_send
cb_reset cb_reset
lb_msgs lb_msgs
st_4 st_4
sle_hostname sle_hostname
st_1 st_1
st_2 st_2
sle_port sle_port
end type
global u_tabpg_udp_send u_tabpg_udp_send

type prototypes

end prototypes

type variables

end variables

on u_tabpg_udp_send.create
int iCurrent
call super::create
this.cb_sendblob=create cb_sendblob
this.sle_message=create sle_message
this.st_3=create st_3
this.cb_send=create cb_send
this.cb_reset=create cb_reset
this.lb_msgs=create lb_msgs
this.st_4=create st_4
this.sle_hostname=create sle_hostname
this.st_1=create st_1
this.st_2=create st_2
this.sle_port=create sle_port
iCurrent=UpperBound(this.Control)
this.Control[iCurrent+1]=this.cb_sendblob
this.Control[iCurrent+2]=this.sle_message
this.Control[iCurrent+3]=this.st_3
this.Control[iCurrent+4]=this.cb_send
this.Control[iCurrent+5]=this.cb_reset
this.Control[iCurrent+6]=this.lb_msgs
this.Control[iCurrent+7]=this.st_4
this.Control[iCurrent+8]=this.sle_hostname
this.Control[iCurrent+9]=this.st_1
this.Control[iCurrent+10]=this.st_2
this.Control[iCurrent+11]=this.sle_port
end on

on u_tabpg_udp_send.destroy
call super::destroy
destroy(this.cb_sendblob)
destroy(this.sle_message)
destroy(this.st_3)
destroy(this.cb_send)
destroy(this.cb_reset)
destroy(this.lb_msgs)
destroy(this.st_4)
destroy(this.sle_hostname)
destroy(this.st_1)
destroy(this.st_2)
destroy(this.sle_port)
end on

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

end event

event destructor;call super::destructor;of_setreg("udp_send_hostname", sle_hostname.text)
of_setreg("udp_send_port",     sle_port.text)
of_setreg("udp_send_message",  sle_message.text)

end event

event ue_postopen;call super::ue_postopen;String ls_hostname

ls_hostname = gn_ws.of_GetHostName()

sle_hostname.text = of_getreg("udp_send_hostname", ls_hostname)
sle_port.text     = of_getreg("udp_send_port", "")
sle_message.text  = of_getreg("udp_send_message", "")

end event

type cb_sendblob from commandbutton within u_tabpg_udp_send
integer x = 37
integer y = 704
integer width = 480
integer height = 100
integer taborder = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Send a Blob"
end type

event clicked;Blob lblb_filedata
Integer li_rtn, li_fnum
Long ll_bytes, ll_MaxMsgSize, ll_last
String ls_fullname, ls_filename
String ls_hostname, ls_ipaddress[], ls_hostaddr, ls_message
UInt lui_port

ls_hostname = sle_hostname.text
If ls_hostname = "" Then
   sle_hostname.SetFocus()
   MessageBox("Edit Error", "Server Host Name is required!")
   Return
End If

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

// get IP Address of the host
If Not gn_ws.of_GetIPAddress(ls_hostname, ls_ipaddress) Then
   ls_message = gn_ws.of_GetLastError()
   lb_msgs.AddItem(ls_message)
   MessageBox("Get IP Address Failed", &
      ls_message, StopSign!)
   Return
End If

// use the last IP Address
ll_last = UpperBound(ls_ipaddress)
ls_hostaddr = ls_ipaddress[ll_last]

// get the file name
li_rtn = GetFileOpenName("Select File", &
            ls_fullname, ls_filename, "", &
            "All files (*.*),*.*")
If li_rtn < 1 Then Return

SetPointer(HourGlass!)

// check the max data size
ll_MaxMsgSize = gn_ws.of_GetMaxMsgSize()
If FileLength(ls_fullname) > ll_MaxMsgSize Then
   MessageBox("Edit Error", &
         "The file is larger than the maximum UDP " + &
         "message size of " + String(ll_MaxMsgSize) + &
         " bytes. You must send the data in parts and " + &
         "combine them at the destination!", StopSign!)
   Return
End If

// get a file into a blob
li_fnum = FileOpen(ls_fullname, StreamMode!)
If li_fnum > 0 Then
   ll_bytes = FileRead(li_fnum, lblb_filedata)
   FileClose(li_fnum)
   lb_msgs.AddItem("Bytes to send: " + String(ll_bytes, "#,##0"))
   If ll_bytes < 1 Then
      MessageBox("FileReadEx", "Failed!", StopSign!)
      Return
   End If
Else
   MessageBox("FileOpen", "Failed!", StopSign!)
   Return
End If

// send the message
If gn_ws.of_SendTo(ls_hostaddr, lui_port, lblb_filedata) Then
   lb_msgs.AddItem("Msg Sent")
Else
   ls_message = gn_ws.of_GetLastError()
   lb_msgs.AddItem(ls_message)
   MessageBox("Send To Failed", &
      ls_message, StopSign!)
End If

SetPointer(Arrow!)

end event

type sle_message from singlelineedit within u_tabpg_udp_send
integer x = 37
integer y = 416
integer width = 1248
integer height = 80
integer taborder = 40
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

event getfocus;cb_send.Default = True

end event

event losefocus;cb_send.Default = False

end event

type st_3 from statictext within u_tabpg_udp_send
integer x = 37
integer y = 356
integer width = 270
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 = "Message:"
boolean focusrectangle = false
end type

type cb_send from commandbutton within u_tabpg_udp_send
integer x = 37
integer y = 544
integer width = 480
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 = "Send a String"
end type

event clicked;Long ll_last
String ls_hostname, ls_ipaddress[], ls_hostaddr, ls_message
UInt lui_port

SetPointer(HourGlass!)

ls_hostname = sle_hostname.text
If ls_hostname = "" Then
   sle_hostname.SetFocus()
   MessageBox("Edit Error", "Server Host Name is required!")
   Return
End If

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

ls_message = sle_message.text
If ls_message = "" Then
   sle_message.SetFocus()
   MessageBox("Edit Error", "Message is required!")
   Return
End If

// get IP Address of the host
If Not gn_ws.of_GetIPAddress(ls_hostname, ls_ipaddress) Then
   ls_message = gn_ws.of_GetLastError()
   lb_msgs.AddItem(ls_message)
   MessageBox("Get IP Address Failed", &
      ls_message, StopSign!)
   Return
End If

// use the last IP Address
ll_last = UpperBound(ls_ipaddress)
ls_hostaddr = ls_ipaddress[ll_last]

// send the message
gn_ws.of_SetUnicode(w_main.cbx_setunicode.checked)
If gn_ws.of_SendTo(ls_hostaddr, lui_port, ls_message) Then
   lb_msgs.AddItem("Msg Sent: " + ls_message)
Else
   ls_message = gn_ws.of_GetLastError()
   lb_msgs.AddItem(ls_message)
   MessageBox("Send To Failed", &
      ls_message, StopSign!)
End If

end event

type cb_reset from commandbutton within u_tabpg_udp_send
integer x = 951
integer y = 1248
integer width = 334
integer height = 100
integer taborder = 70
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_send
integer x = 1353
integer y = 96
integer width = 1541
integer height = 1252
integer taborder = 80
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_4 from statictext within u_tabpg_udp_send
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

type sle_hostname from singlelineedit within u_tabpg_udp_send
integer x = 219
integer y = 104
integer width = 1065
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
borderstyle borderstyle = stylelowered!
end type

type st_1 from statictext within u_tabpg_udp_send
integer x = 37
integer y = 116
integer width = 160
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 = "Host:"
boolean focusrectangle = false
end type

type st_2 from statictext within u_tabpg_udp_send
integer x = 37
integer y = 236
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 sle_port from singlelineedit within u_tabpg_udp_send
integer x = 219
integer y = 224
integer width = 224
integer height = 80
integer taborder = 30
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