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

VB TCP/IP Server (Gateway) for KiX
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    KiXforms Forum Index -> Discussion
View previous topic :: View next topic  
Author Message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Mon Aug 02, 2004 12:44 pm    Post subject: VB TCP/IP Server (Gateway) for KiX Reply with quote

The single issue I struggle with the most when trying to make use of KiX and Kixforms is a lack of COM events which keeps me from using TCP/IP effectively.

I like TCP/IP. TCP/IP likes me. I want to take advantage of the wonderful world of packet communication instead of relying solely on file access.

As such, I am starting work on a VB TCP/IP server that should interface with a KiX script. My goal for this server is for it to handle all the network connections so that a client KiX script can communicate to a server KiX script via the VB Server app. A gateway of sorts that can keep up with the multiple connections. A nice feature of this design will be that if KiX ever got COM events, then this app could be re-written in KiX and no other scripts should have to be modified to keep using it.

The VB server will manage all the connections via an array of sockets. A predetermined socket # will be reserved for the KiX server script to connect to. This connection will always be on and will effectively control the VB server. (Stop/Start/Kill/Poll Info/etc)

Basically, I am seeing if there is any interest for others to use this. If there is, then I'll keep this forum up-to-date on its status, and release it for people to use if desired.

At this time, the server requires an .ocx file (the clients can use this same file for communication) and I would assume VB6 runtime files since that is what I am writing it in.

_________________
-Ben
Back to top
View user's profile Send private message
Chris S.
KiXforms Enthusiast
KiXforms Enthusiast


Joined: 05 Mar 2003
Posts: 241

PostPosted: Mon Aug 02, 2004 1:02 pm    Post subject: Reply with quote

Sounds interesting. Any thought on adding support for FTP? I've found lots of FTP objects I can use for basic FTP stuff, but what really interests me is being able to display file transfer progress. All the ones that support that use events.
Back to top
View user's profile Send private message MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 02, 2004 1:06 pm    Post subject: Reply with quote

oh boy - not sure if you want to hear this or not, im currently putting socket support into kixforms - i need for an internal application in my company - not sure if this will help or hinder what your doing.

-Shawn
Back to top
View user's profile Send private message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Mon Aug 02, 2004 1:17 pm    Post subject: Reply with quote

I finally got so so flustered last night working on a personal project that I decided to write the VB app. I have it working on a basic level, and the next step is to get the KiX script to interact with it.

I'm basically saying that I am just getting started with this, so if you are creating an alternative, then I will probably abandon this effort and go with your method.

Can you provide any details on what this socket support will allow us to do? And can one script handle multiple connections?

We are always excited to hear what new-fangled thingies you are adding to Kixforms!!!

_________________
-Ben


Last edited by Bonji on Mon Aug 02, 2004 1:20 pm; edited 2 times in total
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 02, 2004 1:19 pm    Post subject: Reply with quote

Well, i started this about the middle of last week. Let me post the latest dev build and you can give it a shot - still much to work out ! One sec.
Back to top
View user's profile Send private message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Mon Aug 02, 2004 1:25 pm    Post subject: Reply with quote

I'm just glad that I mentioned this. It would be bad if I spent a week or so working on this, and then develop scripts around it only to have my efforts duplicated by a superior implementation.
_________________
-Ben
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 02, 2004 1:26 pm    Post subject: Reply with quote

Ok, heres the first script - it first opens a listener socket to listen for connections on port 777, it use the OnAccept event to accept connections. Once a connection is accepted, a new client socket is created and this is added to a Collection of active sockets. Events are then tied to the OnReceive and OnDisconnect event. The listener just echos back whatever a client sends it ... the other script is the "client", it establishes a connection witht the server, and sends it data. I've just been testing with running on the local machine for now ... got much more to say about this socket stuff, and questions too, but here are the scripts. Run them from seperate command windows, or use WKIX32.

I have already updated the dev. build with socket support, but its way not finished yet.


SocketListener.kix

Code:

break on

$system = createobject("kixtart.system")

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

$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.onaccept = "accept()"
$listener.port = 777
$listener.bind()

$sockets = $system.collection()

$form.show
$listener.listen

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

exit 1

function accept()

 dim $socket

 $socket = $listener.accept()

 if $socket

  $socket.onreceive = "receive($$system.eventobject)"
  $socket.ondisconnect = "disconnect($$system.eventobject)"

  $sockets.add($socket)

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

 endif

endfunction

function receive($socket)

 dim $text

 $text = $socket.receive()

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

 $socket.send($text)

endfunction

function disconnect($socket)

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

endfunction

function exitclick()

 quit()

endfunction

function clearclick()

 $msgbox.clear()

endfunction


SocketCommander.kix

Code:

break on

$ADDRESS = "127.0.0.1"
$PORT = 777

$system = createobject("kixtart.system")

$form = $system.form()
$form.size = 450, 200
$form.font = $system.font("verdana",10)
$form.text = "SocketCommander"

$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
$sndtxt.text = "<message>"

$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"

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

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

exit 1

function connect()

 $socket = $system.socket()

 if $socket

  $socket.connect($txtip.text, $txtport.text)

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

  $nul = $socket.read()

 endif

endfunction

function send()

 if $socket

  $socket.send($sndtxt.text)

  $rcvtxt.text = $socket.receive()

 endif

endfunction

function disconnect()

 if $socket

  $socket.disconnect()

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

 endif

endfunction
Back to top
View user's profile Send private message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Mon Aug 02, 2004 1:33 pm    Post subject: Reply with quote

Very nice!!!! I look forward to working with this!

I was able to get multiple clients connected just fine and it was able to differentiate between them effectively. This looks to be a great start Shawn!

_________________
-Ben
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 02, 2004 1:40 pm    Post subject: Reply with quote

Its a start - but there are a few issues to be worked out. I could use your help ...

1) Not totally happy with the object model - right now its kinda a mix-mash of dotnet and socketwrench !

2) The sockets used are non-blocking, thats why you might have seen that the first client SEND you do doesn't echo back right away, it does the Receive too fast and catches it on the next Send/Receieve. i'm trying to figure out a way to integreate non-blocking and blocking in the same model.

If you can work a better model, in terms of objects and property/method names, would love to hear it ...
Back to top
View user's profile Send private message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Mon Aug 02, 2004 2:00 pm    Post subject: Reply with quote

I'll definately let you know if I have any thoughts concerning the socket support.

I did notice the receive was always one operation behind. I'm not sure if a socket can be changed from non-blocking to blocking once created (and back again) as I have mostly worked with sockets in KiX. And without events I have the most success using [EDIT] blocking [/EDIT] sockets exclusively.

I was working with your client script, and let me know if I'm off the mark here, but I made a change that might work around this? Basically, I'm using the same receive event that your server uses to update the rcvtxt.text property.

Code:

function connect()

 $socket = $system.socket()

 if $socket

  $socket.connect($txtip.text, $txtport.text)

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

  ;$nul = $socket.read()
  $socket.onreceive = "receive($$system.eventobject)"

 endif

endfunction

FUNCTION RECEIVE($SOCKET)
   $RCVTXT.TEXT = $SOCKET.RECEIVE()
ENDFUNCTION

function send()

 if $socket

  $socket.send($sndtxt.text)
  ;$rcvtxt.text = $socket.receive()

 endif

endfunction


This makes the client read the data as soon as the server sends it. What do you think?

_________________
-Ben


Last edited by Bonji on Mon Aug 02, 2004 3:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 02, 2004 2:31 pm    Post subject: Reply with quote

nice - let me give that a try. How you been working with sockets so far ?

[edit]

ooohhhhh - that works great !
Back to top
View user's profile Send private message
krabourn
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 273
Location: San Antonio. TX

PostPosted: Mon Aug 02, 2004 2:43 pm    Post subject: Reply with quote

This may be slightly off topic, but I think I could write my own ping, WOL, etc. when this is finished. Am I right?
_________________
Kelly
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Shawn
KiXforms Developer
KiXforms Developer


Joined: 22 Feb 2003
Posts: 1983
Location: Canada

PostPosted: Mon Aug 02, 2004 2:52 pm    Post subject: Reply with quote

ping for sure, wol idk ... i'm going to be using this to act as a helpdesk agent, running in the background on thw user's wkstn, it will perform operations under the covers, on the user's bahalf, it will open-up a command prompt to the user, when instructed by the helpdesk. The user won't know how they got the command-prompt and we don't want them to know, we locked the run key down. But they do need it from time-to-time (to help helpdesk debugging).
Back to top
View user's profile Send private message
Bryce
KiXforms Supporter
KiXforms Supporter


Joined: 26 Mar 2003
Posts: 69

PostPosted: Mon Aug 02, 2004 3:09 pm    Post subject: Reply with quote

Laughing Shocked Very Happy
i am all giddy inside!!!
Back to top
View user's profile Send private message
krabourn
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 273
Location: San Antonio. TX

PostPosted: Mon Aug 02, 2004 3:27 pm    Post subject: Reply with quote

If I can actually create the content of the packets sent, then there are many possibilities.

I can feel goosebumps going down my back now.

_________________
Kelly
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Discussion All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
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