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

Socket problem with new build
Goto page 1, 2  Next
 
Post new topic   Reply to topic    KiXforms Forum Index -> Advanced Scripting
View previous topic :: View next topic  
Author Message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Wed Oct 04, 2006 3:25 pm    Post subject: Socket problem with new build Reply with quote

Shawn,

A couple of months ago my socket functionality broke with all of my scripts. I wrote it off to a problem with my laptop because it started happening after I installed the .NET version of Kixforms. I made the (incorrect) assumption that this caused the problem somewhere since it remained even when I put Kixforms classic back. However, it just dawned on me today that I replaced classic Kixforms with a newer version than what I had been using prior to installing .NET Kixforms.

So I installed multiple versions of Kixforms on a different computer and discovered that an older version works when a newer one doesn't. Basically, it looks like socket functionality broke/changed between Kixforms builds 2.46.40.0 and 2.46.54.0.

I have been wanting to pursue various scripting ideas utilizing sockets, but this problem has put a damper on those plans. Very Happy

Here is the script I use to test socket functionality...

Code:

Break On

$System = CreateObject("Kixtart.System")
$cln1Socket = ""
$cln2Socket = ""

$frmMain         = $System.Form()
$frmMain.Size         = 600,480
$frmMain.Text         = "Test Server"
$stsMain         = $frmMain.StatusBar()
$stsMain.Dock         = "Bottom"
$grpMain_Btn         = $frmMain.GroupBox()
$grpMain_Btn.Height      = 40
$grpMain_Btn.Dock      = "Bottom"
$splFirst         = $frmMain.SplitContainer()
$splFirst.Dock         = "Fill"
$splFirst.Orientation      = 0
$grpServer         = $splFirst.Panel1.GroupBox("Server")
$grpServer.Height      = 180
$grpServer.Dock         = "Fill"
$grpServer.DockPadding      = 15
$grpServer_Btn         = $grpServer.GroupBox()
$grpServer_Btn.Height      = 45
$grpServer_Btn.Dock      = "Bottom"
$grpServer_Btn.BorderStyle   = 0
$txtSrvChat         = $grpServer.TextBox()
$txtSrvChat.Height      = 100
$txtSrvChat.Dock      = "Fill"
$txtSrvChat.MultiLine      = 1
$txtSrvChat.AcceptsReturn   = 1
$txtSrvChat.ScrollBars      = 2
$cmdSrvSend         = $grpServer_Btn.Button("Send")
$cmdSrvSend.Size      = 60,19
$cmdSrvSend.Location      = 9,5
$cmdSrvSend.OnClick      = "cmdSrvSend_Click()"
$cmdSrvLstn         = $grpServer_Btn.Button("Listen")
$cmdSrvLstn.Size      = 60,19
$cmdSrvLstn.Location      = 90,5
$cmdSrvLstn.OnClick      = "cmdSrvLstn_Click()"
$cmdSrvStop         = $grpServer_Btn.Button("Stop")
$cmdSrvStop.Size      = 60,19
$cmdSrvStop.Location      = 160,5
$cmdSrvStop.OnClick      = "cmdSrvStop_Click()"
$lblSrvSts1         = $grpServer_Btn.Label("Server Status:")
$lblSrvSts1.Size      = 70,15
$lblSrvSts1.Location      = 10,30
$lblSrvSts2         = $grpServer_Btn.Label("Idle")
$lblSrvSts2.Size      = 480,15
$lblSrvSts2.Location      = 90,30
$splSecond         = $splFirst.Panel2.SplitContainer()
$splSecond.Dock         = "Fill"
$grpClient1         = $splSecond.Panel1.GroupBox("Client 1")
$grpClient1.Dock      = "Fill"
$grpClient1.DockPadding      = 15
$grpClient1_Btn         = $grpClient1.GroupBox()
$grpClient1_Btn.Height      = 45
$grpClient1_Btn.Dock      = "Bottom"
$grpClient1_Btn.BorderStyle   = 0
$txtCln1Chat         = $grpClient1.TextBox()
$txtCln1Chat.Dock      = "Fill"
$txtCln1Chat.MultiLine      = 1
$txtCln1Chat.AcceptsReturn   = 1
$txtCln1Chat.ScrollBars      = 2
$cmdCln1Send         = $grpClient1_Btn.Button("Send")
$cmdCln1Send.Size      = 60,21
$cmdCln1Send.Location      = 10,5
$cmdCln1Send.OnClick      = "cmdCln1Send_Click()"
$cmdCln1Cnct         = $grpClient1_Btn.Button("Connect")
$cmdCln1Cnct.Size      = 60,21
$cmdCln1Cnct.Location      = 80,5
$cmdCln1Cnct.OnClick      = "cmdCln1Cnct_Click()"
$cmdCln1Disc         = $grpClient1_Btn.Button("Disc")
$cmdCln1Disc.Size      = 60,21
$cmdCln1Disc.Location      = 150,5
$cmdCln1Disc.OnClick      = "cmdCln1Disc_Click()"
$lblCln1Sts1         = $grpClient1_Btn.Label("Client Status:")
$lblCln1Sts1.Size      = 70,15
$lblCln1Sts1.Location      = 10,30
$lblCln1Sts2         = $grpClient1_Btn.Label("Idle")
$lblCln1Sts2.Size      = 180,15
$lblCln1Sts2.Location      = 90,30
$grpClient2         = $splSecond.Panel2.GroupBox("Client 2")
$grpClient2.Dock      = "Fill"
$grpClient2.DockPadding      = 15
$grpClient2_Btn         = $grpClient2.GroupBox()
$grpClient2_Btn.Height      = 45
$grpClient2_Btn.Dock      = "Bottom"
$grpClient2_Btn.BorderStyle   = 0
$txtCln2Chat         = $grpClient2.TextBox()
$txtCln2Chat.Dock      = "Fill"
$txtCln2Chat.MultiLine      = 1
$txtCln2Chat.AcceptsReturn   = 1
$txtCln2Chat.ScrollBars      = 2
$cmdCln2Send         = $grpClient2_Btn.Button("Send")
$cmdCln2Send.Size      = 60,21
$cmdCln2Send.Location      = 10,5
$cmdCln2Send.OnClick      = "cmdCln2Send_Click()"
$cmdCln2Cnct         = $grpClient2_Btn.Button("Connect")
$cmdCln2Cnct.Size      = 60,21
$cmdCln2Cnct.Location      = 80,5
$cmdCln2Cnct.OnClick      = "cmdCln2Cnct_Click()"
$cmdCln2Disc         = $grpClient2_Btn.Button("Disc")
$cmdCln2Disc.Size      = 60,21
$cmdCln2Disc.Location      = 150,5
$cmdCln2Disc.OnClick      = "cmdCln2Disc_Click()"
$lblCln2Sts1         = $grpClient2_Btn.Label("Client Status:")
$lblCln2Sts1.Size      = 70,15
$lblCln2Sts1.Location      = 10,30
$lblCln2Sts2         = $grpClient2_Btn.Label("Idle")
$lblCln2Sts2.Size      = 180,15
$lblCln2Sts2.Location      = 90,30
$cmdClose         = $grpMain_Btn.Button("Close")
$cmdClose.Size         = 60,21
$cmdClose.Location      = 270,10
$cmdClose.OnClick      = "$$frmMain = 'Nothing'"
$cmdClose.Cancel      = 1
$cmdDblSend         = $grpMain_Btn.Button("2 Send")
$cmdDblSend.Size      = 60,21
$cmdDblSend.Location      = 10,10
$cmdDblSend.OnClick      = "cmdDblSend_Click()"

$ = $frmMain.Show()
While $frmMain.Visible()
   $ = Execute($frmMain.DoEvents)
Loop

;************************************************
;*      Server Functions      *
;************************************************
Function cmdSrvLstn_Click()
   $Sockets      = $System.Collection()
   $Listener      = $System.Socket()
   $Listener.Blocking   = 0
   $Listener.LocalAddress   = "0.0.0.0"
   $Listener.LocalPort   = "10"
   $Listener.OnAccept   = "evtAccept()"
   $ = $Listener.Bind()
   $ = $Listener.Listen()
   $lblSrvSts2.Text   = "Listening..."
EndFunction

Function evtAccept()
   Dim $Socket
   $Socket = $Listener.Accept()
   If $Socket
      $Socket.Blocking   = 0
      $Socket.OnReceive   = "evtSrv_OnReceive($$System.EventObject)"
      $Socket.OnDisconnect   = "evtSrv_Disconnect($$System.EventObject)"
      $NewSocket = $Sockets.Add($Socket)
      $lblSrvSts2.Text   = $Socket.LocalAddress + " is connected"
   EndIf
EndFunction

Function evtSrv_OnReceive($Socket)
   Dim $Data, $Data_Array
   $Data = $Socket.Receive()
   $Data_Array = Split($Data,"{}{}")
   $ = $txtSrvChat.AppendText("Msg From: " + $Data_Array[0] + " : " + $Data_Array[1] + @CRLF)
EndFunction

Function evtSrv_Disconnect($Socket)
   $lblSrvSts2.Text = "Client " + $Socket.LocalAddress + " disconnected"
   $ = $txtSrvChat.AppendText("A client disconnected" + @CRLF)
   $Cnt = 0
   While $Cnt < $Sockets.Count
      If $Sockets.Item($Cnt).Handle = $Socket.Handle
         $ = $Sockets.Remove($Cnt)
      EndIf
      $Cnt = $Cnt + 1
   Loop
EndFunction

Function cmdSrvStop_Click()
   $Listener = "Nothing"
   If $Sockets.Item(0)
      $ = $Sockets.Item(0).Disconnect()
   EndIf
   If $cln2Socket
      $ = $Sockets.Item(1).Disconnect()
   EndIf
   $lblSrvSts2.Text = "Idle"
EndFunction

Function cmdSrvSend_Click()
   If VarType($Sockets.Item(0)) = 9
      $ = $Sockets.Item(0).Send("Server")
   EndIf
   If VarType($Sockets.Item(1)) = 9
      $ = $Sockets.Item(1).Send("Server")
   EndIf
EndFunction


;************************************************
;*      Client 1 Functions      *
;************************************************
Function cmdCln1Cnct_Click()
   $cln1Socket = $System.Socket()
   If $cln1Socket
      $cln1Socket.Blocking      = 0
      $ = $cln1Socket.Connect("localhost",10)
      $cln1Socket.OnConnect      = "evtCln1_OnConnect($$System.EventObject)"
      $cln1Socket.OnDisconnect   = "evtCln1_Disconnect($$System.EventObject)"
      $cln1Socket.OnReceive      = "evtCln1_OnReceive($$System.EventObject)"
   EndIf
EndFunction

Function evtCln1_OnConnect($cln1Socket)
   If $System.Error
      $ = $frmMain.MessageBox($System.SError,$Ssystem.Error)
      $lblCln1Sts2.Text = "Idle"
      $ = $txtCln1Chat.Clear()
   Else
      $lblCln1Sts2.Text = "Connected to " + $cln1Socket.RemoteAddress
      $ = $txtCln1Chat.Clear()
   EndIf
EndFunction

Function evtCln1_OnReceive($cln1Socket)
   Dim $Data
   $Data = $cln1Socket.Receive()
   $ = $txtCln1Chat.AppendText($Data + @CRLF)
EndFunction

Function evtCln1_Disconnect($cln1Socket)
   $lblCln1Sts2.Text = "Idle"
   $ = $txtCln1Chat.Clear()
EndFunction

Function cmdCln1Send_Click()
   If $cln1Socket
      $ = $cln1Socket.Send("Client1{}{}" + $txtCln1Chat.Text)
      $ = $txtCln1Chat.Clear()
   EndIf
EndFunction

Function cmdCln1Disc_Click()
   $ = $cln1Socket.Disconnect()
   $ = $txtCln1Chat.Clear()
   $lblCln1Sts2.Text = "Idle"
EndFunction


;************************************************
;*      Client 2 Functions      *
;************************************************
Function cmdCln2Cnct_Click()
   $cln2Socket = $System.Socket()
   If $cln2Socket
      $cln2Socket.Blocking      = 0
      $ = $cln2Socket.Connect("localhost",10)
      $cln2Socket.OnConnect      = "evtCln2_OnConnect($$System.EventObject)"
      $cln2Socket.OnDisconnect   = "evtCln2_Disconnect($$System.EventObject)"
      $cln2Socket.OnReceive      = "evtCln2_OnReceive($$System.EventObject)"
   EndIf
EndFunction

Function evtCln2_OnConnect($cln2Socket)
   If $System.Error
      $ = $frmMain.MessageBox($System.SError,$Ssystem.Error)
      $lblCln2Sts2.Text = "Idle"
      $ = $txtCln2Chat.Clear()
   Else
      $lblCln2Sts2.Text = "Connected to " + $cln2Socket.RemoteAddress
      $ = $txtCln2Chat.Clear()
   EndIf
EndFunction

Function evtCln2_OnReceive($cln2Socket)
   Dim $Data
   $Data = $cln2Socket.Receive()
   $ = $txtCln2Chat.AppendText($Data + @CRLF)
EndFunction

Function evtCln2_Disconnect($cln2Socket)
   $lblCln2Sts2.Text = "Idle"
   $ = $txtCln2Chat.Clear()
EndFunction

Function cmdCln2Send_Click()
   If $cln2Socket
      $ = $cln2Socket.Send("Client2{}{}" + $txtCln2Chat.Text)
      $ = $txtCln2Chat.Clear()
   EndIf
EndFunction

Function cmdCln2Disc_Click()
   $ = $cln2Socket.Disconnect()
   $ = $txtCln2Chat.Clear()
   $lblCln2Sts2.Text = "Idle"
EndFunction

;************************************************
;*      Multi Client Functions      *
;************************************************
Function cmdDblSend_Click()
   $Cnt1 = $Cnt1 + 1
   $Cnt2 = $Cnt2 + 1
   If $cln1Socket
      $ = $cln1Socket.Send("Client1{}{}Client1 : " + $Cnt1)
   EndIf
   If $cln2Socket
      $ = $cln2Socket.Send("Client2{}{}Client2 : " + $Cnt2)
   EndIf
EndFunction

_________________
-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: Wed Oct 04, 2006 3:34 pm    Post subject: Reply with quote

Can you tell me, using this script, how to reproduce the issue. Which buttons to push and when.
Back to top
View user's profile Send private message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Wed Oct 04, 2006 3:44 pm    Post subject: Reply with quote

Umm...yeah, that would have been good info to include.

- Click Listen on the top part (Server) to start.
- Click Connect under Client 1.

Clicking Send under the Server will not send anything to Client 1. Also, clicking Send under Client 1 will crash the script because (if I remember correctly) a variable that should be an array is not because the OnReceive event at the server did not contain any data (what is contained in the Client 1 textbox).

When it's working, clicking Send under the Server will send the text "Server" to both of the clients if they are connected. Clicking Send under a Client will send the contents of the client's textbox to the server.

_________________
-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: Wed Oct 04, 2006 4:09 pm    Post subject: Reply with quote

See these here:

$cln2Socket.OnReceive = "evtCln2_OnReceive($$System.EventObject)"

Try changing this:

$$System.EventObject

to this:

$$System.Sender

Let me know if things work better.
Back to top
View user's profile Send private message
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Wed Oct 04, 2006 5:22 pm    Post subject: Reply with quote

It's a much happier script now, and I get to use all the new-fangled gizzies included with the most recent update.

Thanks again!!

_________________
-Ben
Back to top
View user's profile Send private message
SchulieBug
KiXforms Supporter
KiXforms Supporter


Joined: 06 Mar 2003
Posts: 60
Location: Netherlands

PostPosted: Mon Feb 19, 2007 9:53 pm    Post subject: Reply with quote

Bonji, could you please alter the posted code to reflect the changes Shawn proposed. I somehow cannot figure out how it works (due to the error scripts in de sample socket.zip).
_________________
Kind regards
Back to top
View user's profile Send private message Visit poster's website
Bonji
KiXforms Aficionado
KiXforms Aficionado


Joined: 10 Mar 2003
Posts: 393
Location: Virginia

PostPosted: Wed Feb 21, 2007 6:24 pm    Post subject: Reply with quote

Just replace every instance of "EventObject" with "Sender" and that will fix the script.
_________________
-Ben
Back to top
View user's profile Send private message
SchulieBug
KiXforms Supporter
KiXforms Supporter


Joined: 06 Mar 2003
Posts: 60
Location: Netherlands

PostPosted: Wed Feb 21, 2007 7:48 pm    Post subject: Reply with quote

I still get some strange popups when running your script (but it does work?), but due to my dutch os i won't post the here. As soon as i re´nstall my personal notebook (english os) i will test my script again. Thankz!
_________________
Kind regards
Back to top
View user's profile Send private message Visit poster's website
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Wed Feb 21, 2007 7:55 pm    Post subject: Reply with quote

Jochen runs the Dutch version of KiXforms Deutschsprachiges KiXtart/Kixforms forum if your interested but we would be glad to help if we can.
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
SchulieBug
KiXforms Supporter
KiXforms Supporter


Joined: 06 Mar 2003
Posts: 60
Location: Netherlands

PostPosted: Wed Feb 21, 2007 8:12 pm    Post subject: Reply with quote

I found out that at the client part the evtCln1_OnConnect($cln1Socket) event handling (If $System.Error) always gave an error? When i comment the lines for both client parts no error popped up!
_________________
Kind regards
Back to top
View user's profile Send private message Visit poster's website
Sealeopard
KiXforms Aficionado
KiXforms Aficionado


Joined: 05 Mar 2003
Posts: 436
Location: Boston, MA

PostPosted: Fri Feb 23, 2007 4:29 am    Post subject: Reply with quote

Bennie:

Dutch is spoken in The Netherlands (Holland). Jochen definitely speaks German, though he doesn't run the board you linked to. Not sure whether Jochen speaks Dutch, though. Smile

_________________
Jens

'There are two kinds of vessels, submarines and targets.'
Back to top
View user's profile Send private message Send e-mail MSN Messenger
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Fri Feb 23, 2007 12:04 pm    Post subject: Reply with quote

ooops, my bad
_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
SchulieBug
KiXforms Supporter
KiXforms Supporter


Joined: 06 Mar 2003
Posts: 60
Location: Netherlands

PostPosted: Sun Feb 25, 2007 1:00 pm    Post subject: Reply with quote

I'm almost able to run the script in an english environment. Will post the message asap. I don't know if i translate the message to german it will stay the same because my german is a bit rusty (and thats an understatement).
_________________
Kind regards
Back to top
View user's profile Send private message Visit poster's website
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Mon Feb 26, 2007 2:37 pm    Post subject: Reply with quote

┐Que? Stunned
_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
SchulieBug
KiXforms Supporter
KiXforms Supporter


Joined: 06 Mar 2003
Posts: 60
Location: Netherlands

PostPosted: Tue Feb 27, 2007 8:20 pm    Post subject: Reply with quote

Maybe Jochen can translate the message:

'Een niet-blokkerende socketbewerking kan niet onmiddelijk worden voltooid'

This is error 10035. When i remove the 'if $system.error' check in the onconnect($socket) function, it runs normal without problems.

_________________
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 -> Advanced Scripting All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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