Un problemilla con Winsock

Iniciado por Homongus, 19 Agosto 2007, 05:40 AM

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

Homongus

Tras leer un poco de Python, decidí que lo mejor era pulir mis capacidades con VB antes de saltar a otro lenguaje.
Pues bien, me tope con la desagradable sorpresa de que la copia (ilegal) que consegui no contenía los controles active X de Winsock.
Ahora, mi duda es ¿debería conseguir una copia mejor o existe algún sitio donde descargar los controles (aptos para el desarrollo, claro)?
Gracias.

HaDeS, -

Entra a http://www.ascentive.com/support/new/support_dll.phtml?dllname=MSWINSCK.OCX y descarga el fichero que te indican, ahi mismo te dicen como activar el componente y a donde lo debes copiar.
saludos y espero que te sirva!

APOKLIPTICO

Tambien podes usar la Api de Winsock directamente, que no necesita el OCX...
Aqui Va...

Código (vb) [Seleccionar]
Declare Function Socket Lib "wsock32.dll" Alias "socket" (ByVal afinet As Integer, ByVal socktype As Integer)

Declare Function connect Lib "wsock32" (ByVal sock As Long, name As SOCK_ADDR, ByVal namelen As Integer) As Long

Declare Function bind Lib "wsock32" (ByVal sock As Long, addr As SOCK_ADDR, ByVal namelen As Long) As Long

Declare Function listen Lib "wsock32.dll" (ByVal sock As Long, ByVal backlog As Integer) As Integer

Declare Function send Lib "wsock32" (ByVal sock As Long, buffer As Any, ByVal length As Long, ByVal flags As Long) As Long

Declare Function recv Lib "wsock32" (ByVal sock As Long, buffer As Any, ByVal length As Long, ByVal flags As Long) As Long

Type IN_ADDR
    S_addr As Long
End Type

Type SOCK_ADDR
    sin_family As Integer
    sin_port As Integer
    sin_addr As IN_ADDR
    sin_zero(0 To 7) As Byte
End Type

Public Const PF_INET = 2
Public Const SOCK_STREAM = 1
Public Const SOCK_DGRAM = 2
Public Const IPPROTO_IP = 0
Public Const IPPROTO_TCP = 6
Public Const IPPROTO_UDP = 17
Public Const INVALID_SOCKET = -1
Public Const SOCKET_ERROR = -1
Public Const INADDR_ANY = &H0
Public Const SOCKET_ERROR = -1
Public Const MSG_OOB = &H1
Public Const MSG_DONTROUTE = &H4
Public Const MSG_OOB = &H1
Public Const MSG_PEEK = &H2


'connect permet de se connecter sur un server distant

Dim CR As Long
Dim sock As Long
Dim RemoteServer As SOCK_ADDR

RemoteServer.sin_family = AF_INET
RemoteServer.sin_port = htons(2000)
RemoteServer.sin_addr.S_addr = inet_addr("XXX.XXX.XXX.XXX")
RemoteServer.sin_zero(0) = 0
CR = connect(sock, RemoteServer, Len(RemoteServer))


'Création d 'un socket

Dim sock As Long
sock = Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)


'Port

Dim CR As Long
Dim LocalServer As SOCK_ADDR
LocalServer.sin_family = AF_INET
LocalServer.sin_port = 0
LocalServer.sin_addr.S_addr = INADDR_ANY
CR = bind(sock, LocalServer, Len(LocalServer))


'listen permet de mettre un socket en attente de connection

Dim CR As Long
Dim sock As Long
CR = listen(sock, 1)

'send permet d'envoyer

Dim CR As Long
Dim longSend As Long
longSend = Len(chaine)
ReDim buff(longSend + 1) As Byte
For i = 1 To longSend
    buff(i - 1) = Asc(Mid(chaine, i, 1))
Next
buff(longSend) = 0
CR = send(sock, buff(0), longSend, 0)


'recv permet de lire dans un socket

Const MAX_BUFF_SIZE = 10000
Dim buff(0 To MAX_BUFF_SIZE) As Byte
Dim sock As Long
Dim CR As Long

CR = recv(sock, buff(0), MAX_BUFF_SIZE, 0)


'closesocket permet de fermer un socket

Dim Result As Long
Dim sock As Long
       
Result = closesocket(sock)


Fuente: Site de programmation en Visual Basic

Espero que te sirva!!
Saludos
AMD Phenom II 1075T X6 @ 290 Mhz x 11 (HT 2036 Mhz NB Link 2616 Mhz) 1.23 Vcore
ASUS M4A89GTD-PRO/USB3
2x2gb G-Skill RipjawsX DDR3 1600 Mhz CL7 (7-8-7-24-25-1T)
Seagate 500 Gb
XFX HD4850 512Mb GDDR3. 650 Mhz/995 Mhz 1.1 Tflops.

Homongus

Muchas gracias a los dos. Un saludo