You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

Tr4d3r

Beginner

  • "Tr4d3r" is male
  • "Tr4d3r" started this thread

Posts: 12

Date of registration: Mar 16th 2009

Location: Caracas, Venezuela - Bogota, Colombia

Occupation: Senior Developer - SLM Sistemas

Hobbies: Developing, Securiy, others

  • Send private message

1

Tuesday, March 17th 2009, 10:00pm

Jabaco and MultiSocket Server

Hello, i want to develop a Socket Server using JABACO ... in VB6 i use a socket array ... the socket(0) is the listener socket, and i create at runtime other sockets that accept the requestid ... here in JABACO i can't see the control arrays .. so i think the concept is something different ... can anyone help me with an example?

Thanks a lot. :thumbup:

Moogly

Beginner

  • "Moogly" is male

Posts: 17

Date of registration: Mar 9th 2009

  • Send private message

2

Wednesday, March 18th 2009, 4:45am

RE: Jabaco and MultiSocket Server

Hello, i want to develop a Socket Server using JABACO ... in VB6 i use a socket array ... the socket(0) is the listener socket, and i create at runtime other sockets that accept the requestid ... here in JABACO i can't see the control arrays .. so i think the concept is something different ... can anyone help me with an example?

Thanks a lot. :thumbup:
Here is some of the code me and Goldenshox used on our project.

Source code

1
2
3
4
   Dim SocketInteger As Integer, SocketList As String
   
  	SocketInteger = SocketInteger + 1
  	SocketList = SocketList & SocketInteger & ";"


We placed that in ConnectionRequest theres a bit more to it but its specific to our server I hope you can work off from this :P

Tr4d3r

Beginner

  • "Tr4d3r" is male
  • "Tr4d3r" started this thread

Posts: 12

Date of registration: Mar 16th 2009

Location: Caracas, Venezuela - Bogota, Colombia

Occupation: Senior Developer - SLM Sistemas

Hobbies: Developing, Securiy, others

  • Send private message

3

Wednesday, March 18th 2009, 4:50pm

RE: RE: Jabaco and MultiSocket Server

Hello, i want to develop a Socket Server using JABACO ... in VB6 i use a socket array ... the socket(0) is the listener socket, and i create at runtime other sockets that accept the requestid ... here in JABACO i can't see the control arrays .. so i think the concept is something different ... can anyone help me with an example?

Thanks a lot. :thumbup:
Here is some of the code me and Goldenshox used on our project.

Source code

1
2
3
4
   Dim SocketInteger As Integer, SocketList As String
   
  SocketInteger = SocketInteger + 1
  SocketList = SocketList & SocketInteger & ";"


We placed that in ConnectionRequest theres a bit more to it but its specific to our server I hope you can work off from this :P
Really Thanks for your help .. but i still don't understand ...

As you know, only one socket can be in Listening State ... so, normally we load a new socket in runtime, and that socket will answer the request

The code you send is for create a new socket (SocketInteger + 1) and putting in a string ";" separated ... but ... what next? how to create the new socket? how to parse, receive, send from this new socket? (In VB6 we use the Index var, to know where the data comes) ...

Thanks :) Tr4d3r

Tr4d3r

Beginner

  • "Tr4d3r" is male
  • "Tr4d3r" started this thread

Posts: 12

Date of registration: Mar 16th 2009

Location: Caracas, Venezuela - Bogota, Colombia

Occupation: Senior Developer - SLM Sistemas

Hobbies: Developing, Securiy, others

  • Send private message

4

Wednesday, March 18th 2009, 5:09pm

New Hope :)

Hello, i can get the new sockets to acept the request :) :) :)

So, now i have a multisocket server accepting connections ... BUT!

I don;t know hot to receive the data because is an array ...

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Public Sockets() As winsock  

Public Sub Form_Load()
   sock.Listen  ' This is the Listening Socket, never touch this state ;)
End Sub

Public Sub sock_ConnectionRequest(requestSocket As Socket)
   Dim Index As Long 
   Index = Ubound(sockets)+1	'Create new Index from the last in the array + 1
   Redim sockets(Index)        	'Redim the array
   Set sockets(index) = New Winsock  	'Load a new instance of the Winsock Control in the container
   sockets(index).Accept requestsocket   'This new instance accept the requestsocket
End Sub

Public Sub sockets_DataArrival(bytesTotal As Long) 'here i dont receive nothing
End Sub

Public Sub sockets()_DataArrival(bytesTotal As Long) 'This make an error because the "()"
End Sub

Public Sub sockets_DataArrival(bytesTotal As Long, Index as long ) 'This is a madness  :evil: 
End Sub


So .. Please help to understand 8)

Tr4d3r

Tr4d3r

Beginner

  • "Tr4d3r" is male
  • "Tr4d3r" started this thread

Posts: 12

Date of registration: Mar 16th 2009

Location: Caracas, Venezuela - Bogota, Colombia

Occupation: Senior Developer - SLM Sistemas

Hobbies: Developing, Securiy, others

  • Send private message

5

Wednesday, March 18th 2009, 6:05pm

Finally ... Code 0.0.1 :)

Ok, after many tests .. i get it to work ... maybe there is another way to doit .. but .. is working right now.

A multiSocketServer with independent getdata ... Here is the code ... thanks all

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Public Sockets() As winsock  

Private Sub Form_Load()
   sock.Listen   'Let's open the port :)
End Sub

Private Sub sock_ConnectionRequest(requestSocket As Socket)
   Dim NewSocket As Winsock 
   Set NewSocket = GetEmptySocket()	'Use the magic function :P
   NewSocket.Accept requestsocket  	'Acept the input client
End Sub

Private Function GetEmptySocket() As Winsock 
   Dim Index As Long
   index = -1
   For i = 0 To Ubound(Sockets)   'Lets see if there is a empty slot in the array
  	If Sockets(i) = Nothing Then   'We found an Empty Slot
     	index = i
     	Exit For  'Exit the loop
  	End If
   Next i
   If index = -1 Then	'We dont found a empty slot, so we grow the array (create a slot)
  	Index = Ubound(Sockets)+1
  	Redim Preserve Sockets(Index)
   End If
   Set Sockets(index) = New Winsock	
   Set GetEmptySocket = sockets(index)	'Load and put the new socket
   '################################################################
   'TODO: Search for Empty Bounds to decrease the size of the array
   '################################################################
End Function
  
Private Sub Timer1_Timer() 'This timer will handle the arrive of data for all the sockets and Generate And Event to handle
   Dim sData As String 
   For i = 0 To Ubound(sockets) 'Let's search in all the sockets
  	If sockets(i) <> Nothing  Then  'If this is a empty Slot then exit
     	If sockets(i).State <> 7 Then   'If this Socket is recently closed  :::TODO::: Generate Event Disconected
        	Set sockets(i) = Nothing 	'Lets remove the instance ... getting an empty slot :)
     	Else
        	sData = sockets(i).GetData   'Lets get the input buffer
        	If sData <> "" Then      	'If there is something in the buffer   
           	msgbox "Data received from socket: " & i & " the data: " & sData  	'MessageBox the Socket Number and the received data
        	End If
     	End If
  	End If
   Next i
End Sub

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

6

Thursday, March 19th 2009, 10:38am

Timer = Polling

Hi,
great! You have implemented a kind of socket pooling with a dynamically growing array of Winsocks.
The drawback is that you need a timer to scan your Winsocks periodically.

My suggestion would be to invent a class "clsMyWinsock" with super class Winsock (Property SuperClass=VB/Winsock).
This class could then overload event handling routines of Winsock.
Whenever something happens to your Winsock, the event handler would take care for it.
I posted a similar solution for Controls in January.

What do you think?

A1880

Tr4d3r

Beginner

  • "Tr4d3r" is male
  • "Tr4d3r" started this thread

Posts: 12

Date of registration: Mar 16th 2009

Location: Caracas, Venezuela - Bogota, Colombia

Occupation: Senior Developer - SLM Sistemas

Hobbies: Developing, Securiy, others

  • Send private message

7

Saturday, March 21st 2009, 12:04am

RE: Timer = Polling

Hi,
great! You have implemented a kind of socket pooling with a dynamically growing array of Winsocks.
The drawback is that you need a timer to scan your Winsocks periodically.

My suggestion would be to invent a class "clsMyWinsock" with super class Winsock (Property SuperClass=VB/Winsock).
This class could then overload event handling routines of Winsock.
Whenever something happens to your Winsock, the event handler would take care for it.
I posted a similar solution for Controls in January.

What do you think?

A1880
i can't be more agree with you ... as you maybe know, this one is my first software in JABACO ... :) ... now, i have a second one .. i will upload later .. is a way to print to LPT (LPT1 in Windows, /dev/lp0 in Linux (*x) ... i don't know much about super classes and herency because i'm a old vb6 developer :P ... but, i know the concept of course ... so .. i will read your post (really thanks) and will make my best to do the superclass (not a hero one :) lol

Thanks a lot ... le't make JABACO the developer tool of the future :P

Tr4d3r

Rate this thread
WoltLab Burning Board