elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Sigue las noticias más importantes de seguridad informática en el Twitter! de elhacker.NET


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP)
| | | |-+  Programación Visual Basic (Moderadores: LeandroA, seba123neo)
| | | | |-+  Necesito ayuda con multiconexion
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Necesito ayuda con multiconexion  (Leído 1,711 veces)
Isótopo

Desconectado Desconectado

Mensajes: 292


Comprende a los demás para comprenderte a tí mismo


Ver Perfil
Necesito ayuda con multiconexion
« en: 30 Octubre 2009, 21:05 pm »

Hola. Estoy intentado hacer un messenger y necesito poder tener varias conexiones al mismo tiempo. He buscado bastante y veo que se puede hacer con winsock mediante array pero lo ideal es con csocketplus. He visto ejemplos y demas pero no se porque no lo consigo siempre me tira errores del tipo "adress already in use" o que no tengo definido el indice de la matriz y estoy bastante perdido. No e conseguido poner a la escucha un puerto mucho menos aceptar conexiones y recibir/enviar datos. Me podeis orientar un poco?? Gracias.


En línea


-Asus Crosshair IV Formula            
-AMD Phenom II X6 1090T 3.94Ghz @1.38V
-Corsair H70
-Sapphire Radeon HD 6970 2GB Dual-Fan
-G.Skill PIS PC3-17066 4GB 1900MHz 7-9-7-20 @1.65V
-WD Caviar Black 500GB
-Seagate Barracuda Green 2TB x2
-Antec TruePower New 750W Modular
-Cooler Master Dominator CM-690
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Necesito ayuda con multiconexion
« Respuesta #1 en: 31 Octubre 2009, 00:50 am »

Adress already in use

Lo que pasa es que no descargas las instancias del cSocketPlus, para eso usa

Código
  1. set ObjetoPrincipalcSopcketPlus = nothing
  2.  

Con esa simple linea se cierran las coneciones y escuchas (Si detienes el proceso a la mitad, entonces no se descargaran las instancia y seguira ese error aun cuando ayas puesto la linea que te puse arriba)

Dulces Lunas!¡.


« Última modificación: 31 Octubre 2009, 00:52 am por ░▒▓BlackZeroҖ▓▒░ » En línea

The Dark Shadow is my passion.
BlackZeroX
Wiki

Desconectado Desconectado

Mensajes: 3.158


I'Love...!¡.


Ver Perfil WWW
Re: Necesito ayuda con multiconexion
« Respuesta #2 en: 31 Octubre 2009, 01:02 am »

Para que no te compleque tanto la vida con el CSocketPlus usa el CSocketMaster y solo agregas un usercontrol con el siguiente codigo:

con esto lo manejaras como si fuese el WinSock mismo. solo que sin la dependencia del OCX.

Código
  1. '**************************************************************************************
  2. 'This code is an example for CSocketMaster
  3. 'by Emiliano Scavuzzo
  4. '**************************************************************************************
  5.  
  6. Option Explicit
  7.  
  8. 'Don't forget to change CSocketMaster class
  9. 'instancing property to PublicNotCreatable
  10.  
  11. 'These are the same events CSocketMaster has
  12. Public Event CloseSck()
  13. Public Event Connect()
  14. Public Event ConnectionRequest(ByVal requestid As Long)
  15. Public Event DataArrival(ByVal bytesTotal As Long)
  16. Public Event Error(ByVal Number As Integer, Description As String, ByVal sCode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  17. Public Event SendComplete()
  18. Public Event SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
  19.  
  20. 'Our socket
  21. Private WithEvents cmSocket As CSocketMaster
  22.  
  23. Private Sub UserControl_Initialize()
  24. 'create an instance of CSocketMaster
  25. Set cmSocket = New CSocketMaster
  26. End Sub
  27.  
  28. Private Sub UserControl_Terminate()
  29. 'destroy instance of CSocketMaster
  30. Set cmSocket = Nothing
  31. End Sub
  32.  
  33. Private Sub UserControl_Resize()
  34. 'this is used to lock control size
  35. UserControl.Width = 420
  36. UserControl.Height = 420
  37. End Sub
  38.  
  39.  
  40. 'Control properties. Every time the control is built
  41. 'the class instance cmSocket is reset, and so the
  42. 'control properties. We use these variables to make
  43. 'control properties persistent.
  44. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  45. Me.LocalPort = PropBag.ReadProperty("LocalPort", 0)
  46. Me.Protocol = PropBag.ReadProperty("Protocol", 0)
  47. Me.RemoteHost = PropBag.ReadProperty("RemoteHost", "")
  48. Me.RemotePort = PropBag.ReadProperty("RemotePort", 0)
  49. Me.Tag = PropBag.ReadProperty("Tag", "")
  50. End Sub
  51.  
  52. Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  53. PropBag.WriteProperty "LocalPort", Me.LocalPort, 0
  54. PropBag.WriteProperty "Protocol", Me.Protocol, 0
  55. PropBag.WriteProperty "RemoteHost", Me.RemoteHost, ""
  56. PropBag.WriteProperty "RemotePort", Me.RemotePort, 0
  57. PropBag.WriteProperty "Tag", Me.Tag, ""
  58. End Sub
  59.  
  60. 'From this point we declare all the 'bridge' functions
  61. 'and properties. The idea is very simple, when user
  62. 'call a function we call cmSocket function, when
  63. 'cmSocket raises an event we raise an event, when user
  64. 'set a property we set cmSocket property, when user
  65. 'retrieves a property we retrieve cmSocket property
  66. 'and pass the result to user.
  67. 'Easy, isn't it?
  68.  
  69. Private Sub cmSocket_CloseSck()
  70. RaiseEvent CloseSck
  71. End Sub
  72.  
  73. Private Sub cmSocket_Connect()
  74. RaiseEvent Connect
  75. End Sub
  76.  
  77. Private Sub cmSocket_ConnectionRequest(ByVal requestid As Long)
  78. RaiseEvent ConnectionRequest(requestid)
  79. End Sub
  80.  
  81. Private Sub cmSocket_DataArrival(ByVal bytesTotal As Long)
  82. RaiseEvent DataArrival(bytesTotal)
  83. End Sub
  84.  
  85. Private Sub cmSocket_Error(ByVal Number As Integer, Description As String, ByVal sCode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  86. RaiseEvent Error(Number, Description, sCode, Source, HelpFile, HelpContext, CancelDisplay)
  87. End Sub
  88.  
  89. Private Sub cmSocket_SendComplete()
  90. RaiseEvent SendComplete
  91. End Sub
  92.  
  93. Private Sub cmSocket_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
  94. RaiseEvent SendProgress(bytesSent, bytesRemaining)
  95. End Sub
  96.  
  97. Public Property Get RemotePort() As Long
  98. RemotePort = cmSocket.RemotePort
  99. End Property
  100.  
  101. Public Property Let RemotePort(ByVal lngPort As Long)
  102. cmSocket.RemotePort = lngPort
  103. End Property
  104.  
  105. Public Property Get RemoteHost() As String
  106. RemoteHost = cmSocket.RemoteHost
  107. End Property
  108.  
  109. Public Property Let RemoteHost(ByVal strHost As String)
  110. cmSocket.RemoteHost = strHost
  111. End Property
  112.  
  113. Public Property Get RemoteHostIP() As String
  114. RemoteHostIP = cmSocket.RemoteHostIP
  115. End Property
  116.  
  117. Public Property Get LocalPort() As Long
  118. LocalPort = cmSocket.LocalPort
  119. End Property
  120.  
  121. Public Property Let LocalPort(ByVal lngPort As Long)
  122. cmSocket.LocalPort = lngPort
  123. End Property
  124.  
  125. Public Property Get State() As SockState
  126. State = cmSocket.State
  127. End Property
  128.  
  129. Public Property Get LocalHostName() As String
  130. LocalHostName = cmSocket.LocalHostName
  131. End Property
  132.  
  133. Public Property Get LocalIP() As String
  134. LocalIP = cmSocket.LocalIP
  135. End Property
  136.  
  137. Public Property Get BytesReceived() As Long
  138. BytesReceived = cmSocket.BytesReceived
  139. End Property
  140.  
  141. Public Property Get SocketHandle() As Long
  142. SocketHandle = cmSocket.SocketHandle
  143. End Property
  144.  
  145. Public Property Get Tag() As String
  146. Tag = cmSocket.Tag
  147. End Property
  148.  
  149. Public Property Let Tag(ByVal strTag As String)
  150. cmSocket.Tag = strTag
  151. End Property
  152.  
  153. Public Property Get Protocol() As ProtocolConstants
  154. Protocol = cmSocket.Protocol
  155. End Property
  156.  
  157. Public Property Let Protocol(ByVal enmProtocol As ProtocolConstants)
  158. cmSocket.Protocol = enmProtocol
  159. End Property
  160.  
  161. Public Sub Accept(requestid As Long)
  162. cmSocket.Accept requestid
  163. End Sub
  164.  
  165. Public Sub Bind(Optional LocalPort As Variant, Optional LocalIP As Variant)
  166. cmSocket.Bind LocalPort, LocalIP
  167. End Sub
  168.  
  169. Public Sub CloseSck()
  170. cmSocket.CloseSck
  171. End Sub
  172.  
  173. Public Sub Connect(Optional RemoteHost As Variant, Optional RemotePort As Variant)
  174. cmSocket.Connect RemoteHost, RemotePort
  175. End Sub
  176.  
  177. Public Sub GetData(ByRef data As Variant, Optional varType As Variant, Optional maxLen As Variant)
  178. cmSocket.GetData data, varType, maxLen
  179. End Sub
  180.  
  181. Public Sub Listen()
  182. cmSocket.Listen
  183. End Sub
  184.  
  185. Public Sub PeekData(ByRef data As Variant, Optional varType As Variant, Optional maxLen As Variant)
  186. cmSocket.PeekData data, varType, maxLen
  187. End Sub
  188.  
  189. Public Sub SendData(data As Variant)
  190. cmSocket.SendData data
  191. End Sub
  192.  
  193. Public Property Get ComplementoID() As String
  194. ComplementoID = Complemento_ID
  195. End Property
  196. Public Property Let ComplementoID(vdata As String)
  197. Complemento_ID = vdata
  198. End Property
  199.  
En línea

The Dark Shadow is my passion.
Isótopo

Desconectado Desconectado

Mensajes: 292


Comprende a los demás para comprenderte a tí mismo


Ver Perfil
Re: Necesito ayuda con multiconexion
« Respuesta #3 en: 31 Octubre 2009, 11:41 am »

Creo que voy mejorando con el csocketplus. Voy a intentar concretar mas el problema. Tengo este code:
Código:
Option Explicit
Public Index1 As Variant
Dim WithEvents carray As CSocketPlus

Private Sub Form_Load()
Set carray = New CSocketPlus
End Sub

Private Sub Listen_Click()
Index1 = 1
carray.ArrayAdd Index1
carray.Bind Index1, txtPort, carray.LocalIP(Index1)
carray.Listen Index1
Label5.Caption = "Escuchando..."
End Sub

Private Sub carray_ConnectionRequest(ByVal Index1 As Variant, ByVal requestID As Long)
carray.CloseSck Index1
carray.Accept Index1, requestID
ListaConexiones.AddItem carray.RemoteHostIP
Index1 = Index1 + Val(1)
carray.ArrayAdd Index1
carray.Bind Index1, txtPuerto, carray.LocalIP(Index1)
carray.Listen Index1
Label5.Caption = "Conectado y Escuchando..."
End

Debo de haber escrito algun disparate o algo porque la escucha funciona pero no recibe conexiones, o al menos esa parte no va del todo bien. No se si tendra que ver que el otro programa que uso para conectarse utiliza el control winsock. Gracias por las respuestas. Un saludo.
En línea


-Asus Crosshair IV Formula            
-AMD Phenom II X6 1090T 3.94Ghz @1.38V
-Corsair H70
-Sapphire Radeon HD 6970 2GB Dual-Fan
-G.Skill PIS PC3-17066 4GB 1900MHz 7-9-7-20 @1.65V
-WD Caviar Black 500GB
-Seagate Barracuda Green 2TB x2
-Antec TruePower New 750W Modular
-Cooler Master Dominator CM-690
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines