CsocketMaster Array

Iniciado por locot3, 19 Junio 2009, 23:36 PM

0 Miembros y 1 Visitante están viendo este tema.

locot3

Buenas y saludos, mi problema es este : nesecito crear un Arreglo con el Csocket master para realizar multiples conexiones con el winsock es facil sinplemente le pongo :

Load winsock(i)
winsock(i).connect x x x

y quisiera poder hacer lo mismo con el Csocket master pero no me deja , talves almomento de las declaraciones haya que cambiar algo porque como vi en el Csocket master por cada sock que vayamos a declarar 1una en el sector de declaraciones publicas y la otra declaracion en el Form principal ,, cualquuier ayuda sera muy bien agradecia !! saludos y adios !!

LeandroA

Hola este tema ya se hablo en el foro si buscas seguramente vas a encontrar la solución, así a la ligera puedo decirte que también esta el usercontrol de esta clase en el cual podes utilizar array, y también creo que el autor creo una clase especialmente para poder trabajar de forma dinámica.

Busca un poco que vas a encontrar tu solución.

Saludos

locot3

Muchas gracia ssi ya encontre algo sobre esto en el foro , y ya logre implementar el CsocketPLUS ahora tengo un problema al poner el index por ejemplo en el winsock el index lo pongo en el panel de PROPIEDADES Index = 0 , aka nesecito hacer lo mismo alguien que pueda ayudarme ?? gracias

seba123neo

Hola, no se si no entendiste o que...ya te dijeron es muy facil...ya pusiste el index = 0 ...si queres hacerlo bien facil buscate un ejemplo del control winsock comun que use arrays que hay un monton y listo..ya tenes el codigo..simplemente cambias el winsock por este "simulador" del winsock..pero que usa CSocketMaster..es todo lo mismo..

saludos.
La característica extraordinaria de las leyes de la física es que se aplican en todos lados, sea que tú elijas o no creer en ellas. Lo bueno de las ciencias es que siempre tienen la verdad, quieras creerla o no.

Neil deGrasse Tyson

burbu_1

Hola locot3,

lo primero que hay que hacer, al igual que con el csocketmaster es definirel csocket que vas a usar


Dim WithEvents csocket1 As CSocketPlus

         
después hay que cargarlo


Set csocket1 = New CSocketPlus


y por último vas añadiendo al array los elemetos que necesites


csocket1.arrayadd 0


este último codigo te añadiría al array el index 0 por el que preguntas, pero el index es de tipo variant y también podrías poner un string por ejemplo csocket1("nuevo_csocket")

aunque está en inglés se entiende bastante bien las instrucciones que vienen con el módulo:


CSocketPlus 1.2 readme file
===========================

NOTE:
Before sending me a bug report you MUST try your code with Winsock Control first to check if there is something wrong with YOUR code and not with CSocketPlus. If you don't explicitly mention that your code works fine with Winsock Control your message will be ignored. I don't like to be rude but you can't imagine how many times people sent me buggy code blaming CSocketMaster.


*** What is CSocketPlus?
========================

CSocketPlus class is a Winsock control substitute that attempts to mimic it's behavior and interface to make it easy to implement. Unlike CSocketMaster, CSocketPlus has the ability to create sockets at runtime.

*** How do you use it?
======================

1) Add CSocketPlus.cls and modSocketPlus.bas to your project.
2) In a Form, Class or UserControl add this line in the declaration area for each socket array you want to use:

Dim WithEvents NameOfArray As CSocketPlus

where 'NameOfArray' is any name you want for the socket array.

3) You need to create the object before you can use it. Add this line in a sub or funtion:

Set NameOfArray = New CSocketPlus

That's it.

*** Adding and removing sockets from the array
==============================================
To add a socket to the array use ArrayAdd member function. You can use a long value or a string as an index to uniquely identify each socket from the array:

ie: NameOfArray.ArrayAdd 23
NameOfArray.ArrayAdd "Client"

Now you can work with your socket as usual, but you have to pass the index as the first argument:

ie: NameOfArray.Listen 23
NameOfArray.Connect "Client", "www.yahoo.com", 80

When an event is raised you can use Index argument to identify which socket generated the event.

To remove a socket from the array use ArrayRemove member function and pass the index as an argument:

ie: NameOfArray.ArrayRemove 23
NameOfArray.ArrayRemove "Client"

To count how many sockets you have in the array use ArrayCount function:

ie: MsgBox "My array has " & NameOfArray.ArrayCount & " sockets"

Finally, to find out if an index is used by the array use ArrayIndexInUse function:

ie: Msgbox "123 is an index: " & NameOfArray.ArrayIndexInUse(123)


*** About Indexes
=================
As stated above you can use a long value or a string as an index for your socket. CSocketPlus doesn't recognize capital letters, so:

* "client" is equal to "Client" and "CLIENT"
* "My first socket" is a valid index
* "%-_-$&/()=" is a valid index
* "" (empty string) is valid index
* 0, -123 and 999999 are valid indexes
* "one", "1", " 1" , "1 " and 1 are five different indexes
* You can use the same index in two different arrays:

ie: FirstArray.ArrayAdd "client" : SecondArray.ArrayAdd "client"

* When you call ArrayAdd and don't pass an index the fuction finds an available long index for you and returns it with the function. This is not recommended because it could take too long.

ie: lngIndex = NameOfArray.ArrayAdd

*** New error codes
===================
These are the new error codes generated by CSocketPlus:

Constant Value Description

sckWrongIndex 40027 Unsupported index type.
This happens when you try to use a variable as an index other than long or string.

sckUsedIndex 40028 This index is already associated with an element of this array.
This error is raised when you try to add two sockets with the same index.

sckMissingIndex 40029 Unknown index.
This error is raised when you try to remove or work with an inexistent socket index.

*** Extra notes
===============
A) Receiving a connection request from one array and accepting with another array is completely valid:

ie:

Private Sub FirstArray_ConnectionRequest(ByVal Index As Variant, ByVal requestID As Long)

SecondArray.ArrayAdd "server"
SecondArray.Accept "server", requestID

end sub

B) Be careful if you are accustomed to use Winsock control. A line like this is valid with any of them:

Socket.Bind 80

When you use Winsock control that line means "bind my socket to port 80". But when you use CSocketPlus that line means "bind my socket with index number 80 to a free port".

C) When you call ArrayAdd the socket isn't created until you need it and it's destroyed when you call CloseSck or ArrayRemove.

D) Removing the debug logs from the class can speed up the work with large arrays in the IDE. This is not necessary when you compile your code.


*** Differences between CSocketPlus and Winsock control
=======================================================

A) Winsock Close function is CloseSck in CSocketPlus.
B) Winsock Close event is CloseSck in CSocketPlus.
C) WndProc function is used to deliver system messages and you should not call it under any circumstance.
D) There are some other differences I intentionally put in CSocketPlus that you shouldn't notice. If you find a major difference that you think shouldn't be there, please let me know.

*** Known issues
================

A) Msgbox
Due to a VB behavior by desing running a project in the IDE that displays a message box created with Msgbox prevents events from occurring. If you really need to use message boxes then you can use  MessageBox api instead. Note that this only happens in the IDE, when you compile your project all events are fired no matter what. For more info check this site:
http://support.microsoft.com/default.aspx?scid=kb;en-us;178078


*** Why not use Winsock control?
================================

Bacause winsock it's a fixed non-modifiable control. Also it is known that Winsock has a memory leak. For more info check this site:
http://support.microsoft.com/default.aspx?scid=kb;en-us;171843


*** Why use a class instead of a control?
=========================================

Using a class instead of a control has some clear benefits. You have total encapsulation, and you could, for example, make a class (or control) that downloads files from internet just passing a URL without knowing how CSocketPlus works internally. You can modify CSocketPlus and add more fancy functions and events. Best of all: you don't have external dependencies.


*** What tha' heck is that subclassing stuff?
=============================================

When you work with winsock you need to subclass a window to receive system's info from the socket. If you are familiar with the concept of subclassing on VB you should know that if you subclass a window and press then End button while in IDE you get a nice GPF and your system crashes. To solve this I use a code based on Paul Caton's WinSubHook2 that can be found at www.planet-source-code.com. If you wanna understand how my subclassing code works you have to understand his first. The asm code for the WndProc is in Subclass.asm file. This subclassing approach is not fully tested yet, so let me know if you get a GPF.


*** Do you need Subclass.asm file?
==================================
No! This is just the source code for the WndProc used when subclassing. You can delete this file if you wish.


*** Why so many Debug logs?
===========================

That's for helping me (and you) to find any possible bug. If you get annoyed you can always erase them or comment them.


*** What's new on 1.2?
======================
* Fixed the bug that wouldn't free listening socket when the end button is pressed
* Now the use of breakpoints doesn't stop the socket messages
* Minor bugs.


*** Bug report
==============

If you have a question firs't check this site:

http://www.geocities.com/anshoku/

I will post FAQs to this page so I don't have to answer a question twice.
If you don't find your answer there you can send me an email, but first read this:

A) If I consider that your question is answered on my page your email will be ignored.
B) Make sure it's a bug! Maybe what you think it's a bug is normal winsock behavior. Use winsock control to check if the malfunction persists.
C) I suppose you know how to work with winsock cause I will not teach you how to do it. So don't ask me something like 'how to make a connection?' or 'how can I make a chat prog?'.
D) If you could send me some sample code to illustrate the bug, that would be great.
E) Don't be a lamer, don't send spam or chain mails.

Emiliano Scavuzzo <anshoku@yahoo.com>
Rosario, Argentina