ariftheruvath
Programmer
i'm using 2 winsock control (winsock.ocx)
1= 'rmtlisten1' handling connection request from client listening to port '9999'
2= 'LIC' which is already stored in object array and the state= 'listening' to available port
it is working well but if the users conneced (ie the no of accepted connection reaches 10 ) it gives an error msg 'In sufficient memory'
****** * D:\MIS\MISSERVER.SCX
Top = 0
Left = 0
Width = 0
Height = 0
Datasource = .Null.
Name = "Dataenvironment"
Top = 25
Left = 0
Height = 386
Width = 442
DoCreate = .T.
Caption = "MIS Server"
ControlBox = .F.
Closable = .F.
Name = "frmServer"
Procedure Init
abcd=Inputbox('Local Port','MisServer Port','9999')
srvport=Val(abcd)&& load this from config File REcommended
Thisform.rmtlisten1.janal.Object.LocalPort = srvport
Thisform.rmtlisten1.janal.Object.Listen
lstport=Thisform.rmtlisten1.janal.Object.LocalPort
This.label1.Caption='Listening to Port : '+Alltrim(Str(lstport))+Chr(13)
This.label2.Caption='Max Users : '+Alltrim(Str(MAX_USERS))+ Chr(13)
Public Array licarray(MAX_USERS)
For i=1 To Alen(licarray)
***create obj array
licarray(i)=Createobject('lic')
licarray(i).janal.Object.LocalPort=0
licarray(i).janal.Object.Listen
licarray(i).Comment=licstring
Endfor
Endif
Endproc
Top = 0
Left = 408
Visible = .F.
Name = "Rmtlisten1"
janal.Top = 0
janal.Left = 0
janal.Height = 100
janal.Width = 100
janal.Name = "janal"
Procedure janal.ConnectionRequest
*** ActiveX Control Event ***
Lparameters requestid
*sckClosed =0 &&Default. Closed
*sckOpen =1 &&Open
*sckListening =2 &&Listening
*sckConnectionPending =3 &&Connection pending
*sckResolvingHost =4 &&Resolving host
*sckHostResolved =5 &&Host resolved
*sckConnecting =6 &&Connecting
*sckConnected =7 &&Connected
*sckClosing =8 &&Peer is closing the connection
*sckError =9 &&Error
If Type('licarray',1)=='A'
***count Users connected already
x=0
For i=1 To MAX_USERS
If licarray(i).janal.Object.state=7 && if connected
x=x+1
Endif
Endfor
Thisform.label3.Caption="Users connected : "+Alltrim(Str(x))
If x=MAX_USERS
Else
**Accept connection to First available socket
For i=1 To MAX_USERS
If licarray(i).janal.Object.state=7
Else
licarray(i).janal.ConnectionRequest(requestid)
Exit
Endif
Endfor
Endif
Endif
Endproc
Procedure ConnectionRequest && Winsock Control ' LIC'
*** ActiveX Control Event ***
Lparameters requestid
This.Object.Close()
*IF THIS.OBJECT.State<>7
This.Object.Accept(requestid)
If This.Object.state=7 && CONNECTED
****code***
Endif
*ENDIF
Endproc