KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Kixforms Sockets : Discussion
Goto page Previous  1, 2, 3, 4, 5, 6
 
Post new topic   Reply to topic    KiXforms Forum Index -> Discussion
View previous topic :: View next topic  
Author Message
Radimus
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 157
Location: Tampa, Florida

PostPosted: Tue Oct 02, 2007 4:07 pm    Post subject: Reply with quote

I've tried the samples and I get failures on every PC I try to use the client on... The server recognizes the connection, but the client fails.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
SchulieBug
KiXforms Supporter
KiXforms Supporter


Joined: 06 Mar 2003
Posts: 60
Location: Netherlands

PostPosted: Wed Oct 03, 2007 6:30 am    Post subject: Reply with quote

You need to alter some settings in the code as wel as using the KixForms standard (not the .Net version). The altered samples are hereunder.

Server:
Code:

break on

;
; ECHO SERVER (LISTENER)
;

$ADDRESS = @WKSTA
$PORT = 1200

$MAXCLIENTS = 5

$system = createobject("kixtart.system")

$form = $system.form()
$form.size = 400,300
$form.font = $system.font("verdana",10)
$form.text = "Echo: Server"
$form.location = 20,20

$statusbar = $form.statusbar()

$msgbox = $form.textbox()
$msgbox.multiline = "true"
$msgbox.dock = "fill"
$msgbox.text = ""
$msgbox.scrollbars = 2

$menu = $system.mainmenu()
$filemenu = $menu.menuitems.add("File")
$exitmenu = $filemenu.menuitems.add("Exit")
$exitmenu.onclick = "exitclick()"

$editmenu = $menu.menuitems.add("Edit")
$clearmenu = $editmenu.menuitems.add("Clear")
$clearmenu.onclick = "clearclick()"

$form.menu = $menu

$listener = $system.socket()

$listener.blocking = 0
$listener.onaccept = "accept()"

$listener.localaddress = @WKSTA
$listener.localport = 1200

$listener.bind()

if $system.error
 $= $system.messagebox.show($system.serror)
 quit()
endif

$msgbox.appendtext("" + $listener.handle + " - Listening " +
   $listener.localaddress + ":" +
   $listener.localport + @CRLF )

$sockets = $system.collection()

$form.show()

$listener.listen()

if $system.error
 $= $system.messagebox.show($system.serror)
 quit()
endif

updatestatus()

while $form.visible
 $= execute($form.doevents)
loop

exit 1

function accept()

 dim $socket, $msg

 if $system.error
  $= $system.messagebox.show($system.serror)
  return
 endif

 $socket = $listener.accept()

 if $socket

  ;; setup socket as non-blocking ...
 
  $socket.blocking = 0
  $socket.onreceive = "receive($$system.eventobject)"
  $socket.ondisconnect = "disconnect($$system.eventobject)"

  ;; add socket to sockets collection, indexed by handle ...
 
  $sockets.add($socket,$socket.handle)

  $msg = "" + $socket.handle + " - " + "Accepted  " + $socket.remoteaddress + ":" + $socket.remoteport

  $msgbox.appendtext($msg + @CRLF)

 endif

 updatestatus()

endfunction

function receive($socket)

 dim $text

 $text = $socket.receive()

 $msgbox.appendtext("" + $socket.handle + " - " + $text + @CRLF )

 $socket.send($text)

endfunction

function disconnect($socket)

 $msgbox.appendtext("" + $socket.handle + " - Disconnected: " + $socket.remoteaddress + ":" + $socket.remoteport + @CRLF)

 ;; remove socket from collection, which also releases it ...

 $sockets.remove(""+$socket.handle)

 updatestatus()

endfunction

function exitclick()

 quit()

endfunction

function clearclick()

 $msgbox.clear()

endfunction

function updatestatus()

 $statusbar.text = "Connections: " + $sockets.count

endfunction


Client:
Code:

break on

$ADDRESS = @WKSTA
$PORT = 670305

$system = createobject("kixtart.system")

$form = $system.form()
$form.size = 450, 230
$form.font = $system.font("verdana",10)
$form.text = "Echo: Client"

$lblip = $form.label("Destination IP:")
$lblip.bounds = 10,20, 120,25
$lblip.textalign = "middleleft"

$txtip = $form.textbox()
$txtip.bounds = $lblip.right + 10, $lblip.top, 180, 25
$txtip.text = $ADDRESS

$lblport = $form.label("Destination Port:")
$lblport.bounds = 10,$lblip.bottom+10, 120,25
$lblport.textalign = "middleleft"

$txtport = $form.textbox()
$txtport.bounds = $lblport.right + 10, $lblport.top, 180, 25
$txtport.text = $PORT

$sndlbl = $form.label("Send:")
$sndlbl.bounds = 10,$lblport.bottom+10, 120,25
$sndlbl.textalign = "middleleft"

$sndtxt = $form.textbox()
$sndtxt.bounds = $sndlbl.right + 10, $sndlbl.top, 180, 25
$msg = 1
$sndtxt.text = "[message#$msg]"

$rcvlbl = $form.label("Receive:")
$rcvlbl.bounds = 10,$sndlbl.bottom+10, 120,25
$rcvlbl.textalign = "middleleft"

$rcvtxt = $form.textbox()
$rcvtxt.bounds = $rcvlbl.right + 10, $rcvlbl.top, 180, 25
$rcvtxt.text = ""

$conbtn = $form.button()
$conbtn.bounds = $txtip.right + 10, $txtip.top, 100, 25
$conbtn.text = "Connect"
$conbtn.onclick = "connect()"

$sndbtn = $form.button()
$sndbtn.bounds = $conbtn.left, $conbtn.bottom+10, 100, 25
$sndbtn.text = "Send"
$sndbtn.onclick = "send()"
$sndbtn.enabled = "false"

$disbtn = $form.button()
$disbtn.bounds = $conbtn.left, $sndbtn.bottom+10, 100, 25
$disbtn.text = "Disconnect"
$disbtn.onclick = "disconnect()"
$disbtn.enabled = "false"

$statusbar = $form.statusbar()
$statusbar.dock = "bottom"

$form.center
$form.show
$txtip.focus()

while $form.visible
 $=execute($form.doevents)
loop

exit 1

function connect()

 $socket = $system.socket()

 if $socket

  $socket.blocking = 0
  $socket.onconnect = "onconnect($$system.eventobject)"
  $socket.onreceive = "onreceive($$system.eventobject)"
  $socket.ondisconnect = "ondisconnect($$system.eventobject)"

  $socket.remoteaddress = @WKSTA
  $socket.remoteport = 670305

  $socket.connect()

 endif

endfunction

function onconnect($socket)

 if $system.error
  $= $system.messagebox.show($system.serror)
  return
 endif

 if $socket

  $conbtn.enabled = "false"
  $sndbtn.enabled = "true"
  $disbtn.enabled = "true"
  $sndbtn.focus()
  $rcvtxt.text = ""

  $statusbar.text = "Connected to " + $socket.remoteaddress + " : " + $socket.remoteport

 endif

endfunction

function send()

 if $socket

  $socket.send($sndtxt.text+';'+'172.31.8.14'+';'+@UserID+';'+@PrimaryGroup+';'+'Holten')

  if $system.error
   $= $system.messagebox.show($system.serror)
   return
  endif

  $msg = $msg + 1

  $sndtxt.text = "[message#$msg]"

 endif

endfunction

function disconnect()

 if $socket

  $socket.disconnect()

  $conbtn.enabled = "true"
  $sndbtn.enabled = "false"
  $disbtn.enabled = "false"
  $conbtn.focus()
  $rcvtxt.text = ""
 
  $socket.close()

  $socket = 0

  $statusbar.text = "Disconnected"

 endif

endfunction

;
; EVENTS
;

function onreceive($socket)

 if $system.error
  $= $system.messagebox.show($system.serror)
  return
 endif

 if $socket

  $rcvtxt.text = $socket.receive()

 endif

endfunction

function ondisconnect($socket)

 $= $system.messagebox.show($system.serror)

 if $socket


 endif

endfunction


(thanks to Shawn)

_________________
Kind regards
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Discussion All times are GMT
Goto page Previous  1, 2, 3, 4, 5, 6
Page 6 of 6

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group