• Jueves 14 de Noviembre de 2024, 23:36

Autor Tema:  Api Winsock  (Leído 3933 veces)

RadicalEd

  • Moderador
  • ******
  • Mensajes: 2430
  • Nacionalidad: co
    • Ver Perfil
Api Winsock
« en: Jueves 9 de Junio de 2005, 20:07 »
0
Este es el manejo de la api Winsock para Visual.
Código: Text
  1. '*************************************************************
  2. '¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
  3. '     Application Programming Inteface (API) for WinSock
  4. '
  5. 'Este módulo contiene todas las declaraciones necesarias para
  6. 'utilizar los sockets de sistema. El funcionamiento y ejemplo
  7. 'de estas funciones se pueden encontrar en MSDN:
  8. '
  9. 'http://msdn.microsoft.com
  10. '
  11. 'Autor: Slasher Keeper :)
  12. 'Fuente: MSDN Library
  13. '
  14. '¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
  15. '**************************************************************
  16.  
  17. Option Explicit
  18.  
  19. #Const WS_CURVERSION = 2
  20.  
  21.  
  22. Public Const WS_VERSION_REQD = &H101
  23. Public Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
  24. Public Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
  25. Public Const MIN_SOCKETS_REQD = 1
  26. Public Const SOCKET_ERROR = -1
  27. Public Const WSADescription_Len = 256
  28. Public Const WSASYS_Status_Len = 128
  29. Public Const FD_SETSIZE = 64
  30.  
  31. 'Network Events.
  32. '
  33. Public Const FD_READ_BIT = 0
  34. Public Const FD_READ = 1
  35. Public Const FD_WRITE_BIT = 1
  36. Public Const FD_WRITE = 2
  37. Public Const FD_OOB_BIT = 2
  38. Public Const FD_OOB = 4
  39. Public Const FD_ACCEPT_BIT = 3
  40. Public Const FD_ACCEPT = 8
  41. Public Const FD_CONNECT_BIT = 4
  42. Public Const FD_CONNECT = 16
  43. Public Const FD_CLOSE_BIT = 5
  44. Public Const FD_CLOSE = 32
  45. Public Const FD_QOS_BIT = 6
  46. Public Const FD_QOS = 64
  47. Public Const FD_GROUP_QOS_BIT = 7
  48. Public Const FD_GROUP_QOS = 128
  49. Public Const FD_ROUTING_INTERFACE_CHANGE_BIT = 8
  50. Public Const FD_ROUTING_INTERFACE_CHANGE = 256
  51. Public Const FD_ADDRESS_LIST_CHANGE_BIT = 9
  52. Public Const FD_ADDRESS_LIST_CHANGE = 512
  53. Public Const FD_MAX_EVENTS = 10
  54. Public Const FD_ALL_EVENTS = 1023
  55.  
  56. 'Namespaces.
  57. '
  58. Public Const NS_ALL = 0
  59.  
  60. Public Const NS_SAP = 1
  61. Public Const NS_NDS = 2
  62. Public Const NS_PEER_BROWSE = 3
  63.  
  64. Public Const NS_TCPIP_LOCAL = 10
  65. Public Const NS_TCPIP_HOSTS = 11
  66. Public Const NS_DNS = 12
  67. Public Const NS_NETBT = 13
  68. Public Const NS_WINS = 14
  69.  
  70. Public Const NS_NBP = 20
  71.  
  72. Public Const NS_MS = 30
  73. Public Const NS_STDA = 31
  74. Public Const NS_NTDS = 32
  75.  
  76. Public Const NS_X500 = 40
  77. Public Const NS_NIS = 41
  78. Public Const NS_NISPLUS = 42
  79.  
  80. Public Const NS_WRQ = 50
  81.  
  82. Public Const SERVICE_REGISTER = 1
  83. Public Const SERVICE_DEREGISTER = 2
  84. Public Const SERVICE_FLUSH = 3
  85. Public Const SERVICE_FLAG_HARD = &H2
  86.  
  87. Enum SearchControlFlags
  88.   LUP_DEEP = &H1
  89.   LUP_CONTAINERS = &H2
  90.   LUP_NOCONTAINERS = &H4
  91.   LUP_NEAREST = &H8
  92.   LUP_RETURN_NAME = &H10
  93.   LUP_RETURN_TYPE = &H20
  94.   LUP_RETURN_VERSION = &H40
  95.   LUP_RETURN_COMMENT = &H80
  96.   LUP_RETURN_ADDR = &H100
  97.   LUP_RETURN_BLOB = &H200
  98.   LUP_RETURN_ALIASES = &H400
  99.   LUP_RETURN_QUERY_STRING = &H800
  100.   LUP_RETURN_ALL = &HFF0
  101.   LUP_RES_SERVICE = &H8000
  102.   LUP_FLUSHCACHE = &H1000
  103.   LUP_FLUSHPREVIOUS = &H2000
  104. End Type
  105.  
  106.  
  107. 'Protocolos
  108. '
  109. Enum SockProtocols
  110.   IPPROTO_IP = 0                           'dummy for IP
  111.   IPPROTO_ICMP = 1                         'control message protocol
  112.   IPPROTO_IPIP = 4
  113.   IPPROTO_GGP = 2                          ' gateway^2 (deprecated)
  114.   IPPROTO_TCP = 6                          ' tcp
  115.   IPPROTO_EGP = 8
  116.   IPPROTO_PUP = 12                         ' pup
  117.   IPPROTO_UDP = 17                         ' user datagram protocol
  118.   IPPROTO_IDP = 22                         ' xns idp
  119.   IPPROTO_ND = 77                          ' UNOFFICIAL net disk proto
  120.   NSPROTO_IPX = 1000
  121.   NSPROTO_SPX = 1256
  122.   NSPROTO_SPXII = 1257
  123. End Enum
  124.  
  125. 'Socket types.
  126. '
  127. Enum SockTypes
  128.   SOCK_STREAM = 1 'Envía datos como flujo de bytes.
  129.   SOCK_DGRAM = 2  'Datagrama. Protocolo de conexión.
  130.   SOCK_RAW = 3    '???
  131.   SOCK_RDM = 4    'Reliably-Delivered Message (Mensaje confiablemente-entregado)
  132.                   'Es un protocolo que conserva los límites del mensaje en los
  133.                   'datos
  134.   SOCK_SEQPACKET = 5  'Flujo de paquetes secuenciados. Es esencialmente igual
  135.                       'que SOCK_RDM.
  136. End Enum
  137.  
  138. Enum SockPorts
  139.   '
  140.   'Standard well-known ports
  141.   '
  142.   IPPORT_ECHO = 7
  143.   IPPORT_DISCARD = 9
  144.   IPPORT_SYSTAT = 11
  145.   IPPORT_DAYTIME = 13
  146.   IPPORT_NETSTAT = 15
  147.   IPPORT_FTP = 21
  148.   IPPORT_TELNET = 23
  149.   IPPORT_SMTP = 25
  150.   IPPORT_TIMESERVER = 37
  151.   IPPORT_NAMESERVER = 42
  152.   IPPORT_WHOIS = 43
  153.   IPPORT_MTP = 57
  154.  
  155.   IPPORT_TFTP = 69
  156.   IPPORT_RJE = 77
  157.   IPPORT_FINGER = 79
  158.   IPPORT_TTYLINK = 87
  159.   IPPORT_SUPDUP = 95
  160.  
  161.   IPPORT_EXECSERVER = 512
  162.   IPPORT_LOGINSERVER = 513
  163.   IPPORT_CMDSERVER = 514
  164.   IPPORT_EFSSERVER = 520
  165.  
  166.   'UDP ports.
  167.   '
  168.   IPPORT_BIFFUDP = 512
  169.   IPPORT_WHOSERVER = 513
  170.   IPPORT_ROUTESERVER = 520
  171.  
  172.   'Los puertos menores a este valor están reservados para
  173.   'procesos con provilegios.
  174.   '
  175.   IPPORT_RESERVED = 1024
  176.  
  177.   'Los puertos mayores a este valor están reservados para
  178.   'procesos sin privilegios.
  179.   '
  180.   IPPORT_USERRESERVED = 5000
  181.  
  182. End Enum
  183.  
  184. Enum SockErrors
  185.   '
  186.   'Windows Sockets definitions of regular Berkeley error constants
  187.   '
  188.  
  189.    WSABASEERR = 10000
  190.    WSAEWOULDBLOCK = (WSABASEERR + 35)
  191.    WSAEINPROGRESS = (WSABASEERR + 36)
  192.    WSAEALREADY = (WSABASEERR + 37)
  193.    WSAENOTSOCK = (WSABASEERR + 38)
  194.    WSAEDESTADDRREQ = (WSABASEERR + 39)
  195.    WSAEMSGSIZE = (WSABASEERR + 40)
  196.    WSAEPROTOTYPE = (WSABASEERR + 41)
  197.    WSAENOPROTOOPT = (WSABASEERR + 42)
  198.    WSAEPROTONOSUPPORT = (WSABASEERR + 43)
  199.    WSAESOCKTNOSUPPORT = (WSABASEERR + 44)
  200.    WSAEOPNOTSUPP = (WSABASEERR + 45)
  201.    WSAEPFNOSUPPORT = (WSABASEERR + 46)
  202.    WSAEAFNOSUPPORT = (WSABASEERR + 47)
  203.    WSAEADDRINUSE = (WSABASEERR + 48)
  204.    WSAEADDRNOTAVAIL = (WSABASEERR + 49)
  205.    WSAENETDOWN = (WSABASEERR + 50)
  206.    WSAENETUNREACH = (WSABASEERR + 51)
  207.    WSAENETRESET = (WSABASEERR + 52)
  208.    WSAECONNABORTED = (WSABASEERR + 53)
  209.    WSAECONNRESET = (WSABASEERR + 54)
  210.    WSAENOBUFS = (WSABASEERR + 55)
  211.    WSAEISCONN = (WSABASEERR + 56)
  212.    WSAENOTCONN = (WSABASEERR + 57)
  213.    WSAESHUTDOWN = (WSABASEERR + 58)
  214.    WSAETOOMANYREFS = (WSABASEERR + 59)
  215.    WSAETIMEDOUT = (WSABASEERR + 60)
  216.    WSAECONNREFUSED = (WSABASEERR + 61)
  217.    WSAELOOP = (WSABASEERR + 62)
  218.    WSAENAMETOOLONG = (WSABASEERR + 63)
  219.    WSAEHOSTDOWN = (WSABASEERR + 64)
  220.    WSAEHOSTUNREACH = (WSABASEERR + 65)
  221.    WSAENOTEMPTY = (WSABASEERR + 66)
  222.    WSAEPROCLIM = (WSABASEERR + 67)
  223.    WSAEUSERS = (WSABASEERR + 68)
  224.    WSAEDQUOT = (WSABASEERR + 69)
  225.    WSAESTALE = (WSABASEERR + 70)
  226.    WSAEREMOTE = (WSABASEERR + 71)
  227.    WSAEDISCON = (WSABASEERR + 101)
  228. End Enum
  229.  
  230. Enum SockAddressFamilies
  231.    AF_UNSPEC = 0                    'unspecified
  232.    AF_UNIX = 1                      'local to host (pipes, portals)
  233.    AF_INET = 2                      'internetwork: UDP, TCP, etc.
  234.    AF_IMPLINK = 3                   'arpanet imp addresses
  235.    AF_PUP = 4                       'pup protocols: e.g. BSP
  236.    AF_CHAOS = 5                     'mit CHAOS protocols
  237.    AF_IPX = 6                       'IPX and SPX
  238.    AF_NS = 6                        'XEROX NS protocols
  239.    AF_ISO = 7                       'ISO protocols
  240.    AF_OSI = AF_ISO                  'OSI is ISO
  241.    AF_ECMA = 8                      'european computer manufacturers
  242.    AF_DATAKIT = 9                   'datakit protocols
  243.    AF_CCITT = 10                    'CCITT protocols, X.25 etc
  244.    AF_SNA = 11                      'IBM SNA
  245.    AF_DECnet = 12                   'DECnet
  246.    AF_DLI = 13                      'Direct data link interface
  247.    AF_LAT = 14                      'LAT
  248.    AF_HYLINK = 15                   'NSC Hyperchannel
  249.    AF_APPLETALK = 16                'AppleTalk
  250.    AF_NETBIOS = 17                  'NetBios-style addresses
  251. End Enum
  252.  
  253. Type SOCKADDR
  254.   sa_family   As Integer
  255.   sa_data     As String * 14
  256. End Type
  257.  
  258. Type IN_ADDR
  259.   s_b1 As Byte
  260.   s_b2 As Byte
  261.   s_b3 As Byte
  262.   s_b4 As Byte
  263.   s_w1 As Integer
  264.   s_w2 As Integer
  265. End Type
  266.  
  267. Type SOCKADDR_IN
  268.   sin_family  As Integer
  269.   sin_port    As Integer
  270.   sin_addr    As IN_ADDR
  271.   sin_zero    As String * 8
  272. End Type
  273.  
  274. Type OVERLAPPED
  275.   Internal      As Long
  276.   InternalHigh  As Long
  277.   Offset        As Long
  278.   OffsetHigh    As Long
  279.   hEvent        As Long
  280. End Type
  281.  
  282. Type CSADDR_INFO
  283.   LocalAddr     As Long
  284.   RemoteAddr    As Long
  285.   iSocketType   As Long
  286.   iProtocol     As SockProtocols
  287. End Type
  288.  
  289. Type HOSTENT
  290.   h_name          As Long     'official name of host
  291.   h_aliases       As Long     'alias list
  292.   h_addrtype      As Integer  'host address type
  293.   h_length        As Integer
  294.   h_addr_list     As Long     'list of addresses
  295. End Type
  296.  
  297.  
  298. Type PROTOENT
  299.   p_name        As String
  300.   p_aliases(15) As String
  301.   p_proto       As Integer
  302. End Type
  303.  
  304. Type SERVENT
  305.   s_name        As String
  306.   s_aliases(15) As String
  307.   s_port        As Integer
  308.   s_proto       As String
  309. End Type
  310.  
  311. Type SERVICE_ADDRESS
  312.   dwAddressType     As Long
  313.   dwAddressFlags    As Long
  314.   dwAddressLength   As Long
  315.   dwPrincipalLength As Long
  316.   lpAddress         As Byte
  317.   lpPrincipal       As Byte
  318. End Type
  319.  
  320. Type SERVICE_ADDRESSES
  321.   dwAddressCount  As Long
  322.   Addresses(1)    As SERVICE_ADDRESS
  323. End Type
  324.  
  325. Type BLOB
  326.   cbSize      As Long
  327.   pBlobData   As Byte
  328. End Type
  329.  
  330. Type SERVICE_INFO
  331.   lpServiceType       As Long
  332.   lpServiceName       As String
  333.   lpComment           As String
  334.   lpLocale            As String
  335.   dwDisplayHint       As Long
  336.   dwVersion           As Long
  337.   dwTime              As Long
  338.   lpMachineName       As String
  339.   lpServiceAddress As SERVICE_ADDRESSES
  340.   ServiceSpecificInfo As BLOB
  341. End Type
  342.  
  343. Type NS_SERVICE_INFO
  344.   dwNameSpace As Long
  345.   ServiceInfo As SERVICE_INFO
  346. End Type
  347.  
  348. Type WSADATA
  349.   wversion          As Integer
  350.   wHighVersion      As Integer
  351.   szDescription(0 To WSADescription_Len) As Byte
  352.   szSystemStatus(0 To WSASYS_Status_Len) As Byte
  353.   iMaxSockets       As Integer
  354.   iMaxUdpDg         As Integer
  355.   lpszVendorInfo    As Long
  356. End Type
  357.  
  358. Type LARGE_INTEGER
  359.   lowpart As Long
  360.   highpart As Long
  361. End Type
  362.  
  363. Type FD_SET
  364.   fd_count              As Long
  365.   fd_array(FD_SETSIZE)  As Long
  366. End Type
  367.  
  368. Type TIMEVAL
  369.   tv_sec  As Long
  370.   tv_usec As Long
  371. End Type
  372.  
  373. Type TRANSMIT_FILE_BUFFERS
  374.   Head        As Long
  375.   HeadLength  As Long
  376.   Tail        As Long
  377.   TailLength  As Long
  378. End Type
  379.  
  380. Type FLOWSPEC
  381.   TokenRate           As Long     'In Bytes/sec
  382.   TokenBucketSize     As Long     'In Bytes
  383.   PeakBandwidth       As Long     'In Bytes/sec
  384.   Latency             As Long     'In microseconds
  385.   DelayVariation      As Long     'In microseconds
  386.   ServiceType         As Integer  'Guaranteed, Predictive,
  387.                                   'Best Effort, etc.
  388.   MaxSduSize          As Long     'In Bytes
  389.   MinimumPolicedSize  As Long     'In Bytes
  390. End Type
  391.  
  392. Type PROTOCOL_INFO
  393.   dwServiceFlags  As Long
  394.   iAddressFamily  As Long
  395.   iMaxSockAddr    As Long
  396.   iMinSockAddr    As Long
  397.   iSocketType     As Long
  398.   iProtocol       As Long
  399.   dwMessageSize   As Long
  400.   lpProtocol      As Long
  401. End Type
  402.  
  403. Declare Function accept Lib "ws2_32" (ByVal sck As Long, addr As SOCKADDR, AddrLen As Integer) As Long
  404.  
  405. Declare Function AcceptEx Lib "ws2_32" (ByVal sListenSocket As Long, ByVal sAcceptSocket As Long, lpOutputBuffer As Any, ByVal dwReceiveDataLength As Long, ByVal dwLocalAddressLength As Long, ByVal dwRemoteAddressLength As Long, lpdwBytesReceived As Long, lpOverlapped As OVERLAPPED) As Long
  406.  
  407. Declare Function bind Lib "ws2_32" (ByVal sck As Long, name As SOCKADDR, ByVal namelen As Long) As Long
  408. Declare Function closesocket Lib "ws2_32" (ByVal sck As Long) As Long
  409.  
  410. Declare Function Connect Lib "ws2_32" (ByVal sck As Long, ByVal SckName As String, ByVal namelen As Long) As Long
  411. Declare Function EnumProtocols Lib "ws2_32" Alias "EnumProtocolsA" (ByVal lpiProtocols As SockProtocols, ByVal lpProtocolBuffer As PROTOCOL_INFO, ByVal lpdwBufferLength As Long)
  412.  
  413. Declare Sub GetAcceptExSockaddrs Lib "ws2_32" (lpOutputBuffer As Any, ByVal dwReceiveDataLength As Long, ByVal dwLocalAddressLength As Long, ByVal dwRemoteAddressLength As Long, LocalSockaddr As Long, LocalSockaddrLength As Long, RemoteSockaddr As Long, RemoteSockaddrLength As Long)
  414.  
  415. Declare Function GetAddressByName Lib "ws2_32" Alias "GetAddressByNameA" (ByVal dwNameSpace As Long, ByVal lpServiceType As Long, ByVal lpServiceName As Long, ByVal lpiProtocols As SockProtocols, ByVal dwResolution As Long, ByVal lpServiceAsyncInfo As Long, lpCsaddrBuffer As CSADDR_INFO, ByVal lpdwBufferLength As Long, ByVal lpAliasBuffer As Long, ByVal lpdwAliasBufferLength As Long) As Long
  416.  
  417. Declare Function gethostbyaddr Lib "ws2_32" (ByVal addr As String, ByVal iaddrlen As Long, ByVal iaddrtype As Long) As HOSTENT
  418.  
  419. Declare Function gethostbyname Lib "ws2_32" (ByVal hostname As String) As Long
  420.  
  421. Declare Function gethostname Lib "ws2_32" (ByVal name As String, ByVal namelen As Long) As Long
  422.  
  423. Declare Function GetNameByType Lib "ws2_32" Alias "GetNameByTypeA" (ByVal lpServiceType As Long, ByVal lpServiceName As String, ByVal dwNameLength As Long) As Long
  424.  
  425. Declare Function getpeername Lib "ws2_32" (ByVal sck As Long, name As SOCKADDR, ByVal namelen As Long) As Long
  426.  
  427. Declare Function getprotobyname Lib "ws2_32" (ByVal name As String) As PROTOENT
  428.  
  429. Declare Function getprotobynumber Lib "ws2_32" (ByVal Number As Long) As PROTOENT
  430.  
  431. Declare Function getservbyname Lib "ws2_32" (ByVal name As String, ByVal proto As String) As SERVENT
  432.  
  433. Declare Function getservbyport Lib "ws2_32" (ByVal port As Integer, ByVal proto As String) As SERVENT
  434.  
  435.  
  436. Declare Function GetService Lib "ws2_32" Alias "GetServiceA" (ByVal dwNameSpace As Long, ByVal lpGuid As Long, ByVal lpServiceName As String, ByVal dwProperties As Long, lpBuffer As NS_SERVICE_INFO, ByVal lpdwBufferSize As Long, ByVal lpServiceAsyncInfo As Long) As Long
  437.  
  438. Declare Function GetSockName Lib "ws2_32" Alias "GetSockNameA" (ByVal sck As Long, name As Long, ByVal namelen As Long) As Long
  439.  
  440. Declare Function getsockopt Lib "ws2_32" (ByVal sck As Long, ByVal level As Long, ByVal optname As Long, ByVal optval As Long, optlen As Long) As Long
  441.  
  442. Declare Function GetTypeByName Lib "ws2_32" Alias "GetTypeByNameA" ()
  443.  
  444. Declare Function htons Lib "ws2_32" (ByVal hostshort As Integer) As Integer
  445.  
  446. Declare Function htonl Lib "ws2_32" (ByVal hostlong As Long) As Long
  447.  
  448. Declare Function inet_addr Lib "ws2_32" (ByVal cp As String) As Long
  449.  
  450. Declare Function inet_ntoa Lib "ws2_32" (pin As IN_ADDR) As Long
  451.  
  452. Declare Function ioctlsocket Lib "ws2_32" (ByVal s As Long, ByVal cmd As Long, ByVal argp As Long) As Integer
  453.  
  454. Declare Function listen Lib "ws2_32" (ByVal s As Long, ByVal backlog As Integer) As Integer
  455.  
  456. Declare Function ntohl Lib "ws2_32" (ByVal netlong As Long) As Long
  457.  
  458. Declare Function ntohs Lib "ws2_32" (ByVal netshort As Integer) As Integer
  459.  
  460. Declare Function recv Lib "ws2_32" (ByVal s As Long, ByVal buf As String, ByVal BufLen As Integer, ByVal flags As Integer) As Integer
  461.  
  462. Declare Function recvfrom Lib "ws2_32" (ByVal s As Long, ByVal buf As String, ByVal BufLen As Integer, ByVal flags As Integer, from As SOCKADDR, fromlen As Integer) As Integer
  463.  
  464. Declare Function sockselect Lib "ws2_32" Alias "select" (ByVal nfds As Integer, readfds As FD_SET, writefds As FD_SET, exceptfds As FD_SET, timeout As TIMEVAL) As Integer
  465.  
  466. Declare Function send Lib "ws2_32" (ByVal s As Long, ByVal buf As Long, ByVal BufLen As Integer, ByVal flags As Integer) As Integer
  467.  
  468. Declare Function sendto Lib "ws2_32" (ByVal s As Long, ByVal buf As Long, ByVal BufLen As Integer, ByVal flags As Integer, sckto As SOCKADDR, ByVal tolen As Integer) As Integer
  469.  
  470. Declare Function SetService Lib "ws2_32" Alias "SetServiceA" (ByVal dwNameSpace As Long, ByVal dwOperation As Long, ByVal dwFlags As Long, lpServiceInfo As SERVICE_INFO, ByVal lpServiceAsyncInfo As Long, ByVal lpdwStatusFlags As Long) As Long
  471.  
  472. Declare Function setsockopt Lib "ws2_32" (ByVal s As Long, ByVal level As Integer, ByVal optname As Integer, ByVal optval As Long, ByVal optlen As Long) As Integer
  473.  
  474. Declare Function shutdown Lib "ws2_32" (ByVal s As Long, ByVal how As Integer) As Integer
  475.  
  476. Declare Function socket Lib "ws2_32" (ByVal iAddressFamily As Long, ByVal iType As Long, ByVal iProtocol As Long) As Long
  477.  
  478. Declare Function TransmitFile Lib "ws2_32" (ByVal hSocket As Long, ByVal hFile As Long, ByVal nNumberOfBytesToWrite As Long, ByVal nNumberOfBytesPerSend As Long, ByVal lpOverlapped As OVERLAPPED, ByVal lpTransmitBuffers As TRANSMIT_FILE_BUFFERS, ByVal dwFlags As Long) As Boolean
  479.  
  480.  
  481. Const MAX_PROTOCOL_CHAIN = 7
  482.  
  483. Type WSAPROTOCOLCHAIN
  484.   ChainLen As Integer   'the length of the chain,
  485.                         'length = 0 means layered protocol,
  486.                         'length = 1 means base protocol,
  487.                         'length > 1 means protocol chain
  488.   ChainEntries(MAX_PROTOCOL_CHAIN) As Long  'a list of dwCatalogEntryIds
  489. End Type
  490.  
  491. Const WSAPROTOCOL_LEN = 255
  492.  
  493. Type WSAPROTOCOL_INFO
  494.     dwServiceFlags1                 As Long
  495.     dwServiceFlags2                 As Long
  496.     dwServiceFlags3                 As Long
  497.     dwServiceFlags4                 As Long
  498.     dwProviderFlags                 As Long
  499.     ProviderId                      As CLSID
  500.     dwCatalogEntryId                As Long
  501.     ProtocolChain                   As WSAPROTOCOLCHAIN
  502.     iVersion                        As Integer
  503.     iAddressFamily                  As Integer
  504.     iMaxSockAddr                    As Integer
  505.     iMinSockAddr                    As Integer
  506.     iSocketType                     As Integer
  507.     iProtocol                       As Integer
  508.     iProtocolMaxOffset              As Integer
  509.     iNetworkByteOrder               As Integer
  510.     iSecurityScheme                 As Integer
  511.     dwMessageSize                   As Integer
  512.     dwProviderReserved              As Integer
  513.     szProtocol(WSAPROTOCOL_LEN + 1) As Byte
  514. End Type
  515.  
  516. Declare Function WSAAccept Lib "ws2_32" (ByVal hSocket As Long, pSockAddr As SOCKADDR, ByVal AddrLen As Integer, ByVal lpfnCondition As Long, ByVal dwCallbackData As Long) As Long
  517.  
  518. Declare Function WSAAddressToString Lib "ws2_32" Alias "WSAAddressToStringA" (lpsaAddress As SOCKADDR, ByVal dwAddressLength As Long, lpProtocolInfo As PROTOCOL_INFO, ByVal lpszAddressString As String, ByVal lpdwAddressStringLength As Long) As Long
  519.  
  520. Declare Function WSAAsyncGetHostByAddr Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal lpNetAddr As Long, ByVal AddrLen As Long, ByVal AddrType As Long, ByVal lpBuf As Long, ByVal BufLen As Long) As Long
  521.  
  522. Declare Function WSAAsyncGetHostByName Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal lpHostName As String, ByVal lpBuf As Long, ByVal BufLen As Long) As Long
  523.  
  524. Declare Function WSAAsyncGetProtoByName Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal lpHostName As String, ByVal lpBuf As Long, ByVal BufLen As Long) As Long
  525.  
  526. Declare Function WSAAsyncGetProtoByNumber Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal iNumer As Integer, ByVal lpBuf As Long, ByVal BufLen As Long) As Long
  527.  
  528. Declare Function WSAAsyncGetServByName Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal lpServiceName As String, ByVal lpProtocolName As String, ByVal lpBuf As Long, ByVal BufLen As Long) As Long
  529.  
  530. Declare Function WSAAsyncGetServByPort Lib "ws2_32" (ByVal hWnd As Long, ByVal wMsg As Integer, ByVal iPort As Integer, ByVal lpProtocolName As String, ByVal lpBuf As Long, ByVal BufLen As Long) As Long
  531.  
  532. Declare Function WSAAsyncSelect Lib "ws2_32" (ByVal hSocket As Long, ByVal hWnd As Long, ByVal wMsg As Integer, ByVal lEvent As Long) As Integer
  533.  
  534. Declare Function WSACancelAsyncRequest Lib "ws2_32" (ByVal hAsyncTaskHandle As Long) As Integer
  535.  
  536. Declare Function WSACleanup Lib "ws2_32" () As Integer
  537.  
  538. Declare Function WSACloseEvent Lib "ws2_32" (ByVal hEvent As Long) As Boolean
  539. Declare Function WSAConnect Lib "ws2_32" (ByVal hSocket As Long, lpSckName As SOCKADDR, ByVal iSckNameLen As Integer, ByVal lpCallerData As Long, lpCalleeData As Long, lpSQOS As FLOWSPEC, lpGQOS As FLOWSPEC) As Integer
  540.  
  541. Declare Function WSACreateEvent Lib "ws2_32" () As Long
  542.  
  543. Declare Function WSADuplicateSocket Lib "ws2_32" Alias "WSADuplicateSocketA" (ByVal hSocket As Long, ByVal dwProcessId As Long, lpProtocolInfo As WSAPROTOCOL_INFO)
  544.  
  545. Type WSANAMESPACE_INFO
  546.   NSProviderId    As CLSID
  547.   dwNameSpace     As Long
  548.   fActive         As Boolean
  549.   dwVersion       As Long
  550.   lpszIdentifier  As Long
  551. End Type
  552.  
  553. Declare Function WSAEnumNameSpaceProviders Lib "ws2_32" Alias "WSAEnumNameSpaceProvidersA" (lpdwBufferLength As Long, lpnspBuffer As Long) As Integer
  554.  
  555. Type WSANETWORKEVENTS
  556.   lNetworkEvents            As Long
  557.   iErrorCode(FD_MAX_EVENTS) As Integer
  558. End Type
  559.  
  560. Declare Function WSAEnumNetworkEvents Lib "ws2_32" (ByVal hSocket As Long, ByVal hEventObject As Long, lpNetworkEvents As WSANETWORKEVENTS)
  561.  
  562. Declare Function WSAEnumProtocols Lib "ws2_32" Alias "WSAEnumProtocolsA" (ByVal lpiProtocols As Long, lpProtocolBuffer As Long, ByVal lpdwBufferLength As Long) As Integer
  563.  
  564.  
  565. Declare Function WSAEventSelect Lib "ws2_32" (ByVal hSocket As Long, ByVal hEventObject As Long, ByVal lNetworkEvents As Long)
  566.  
  567. Declare Function WSAGetLastError Lib "ws2_32" () As Integer
  568.  
  569. Type WSAOVERLAPPED
  570.   Internal      As Long
  571.   InternalHigh  As Long
  572.   Offset        As Long
  573.   OffsetHigh    As Long
  574.   hEvent        As Long
  575. End Type
  576.  
  577. Declare Function WSAGetOverlappedResult Lib "ws2_32" (ByVal hSocket As Long, lpOverlapped As WSAOVERLAPPED, lpcbTransfer As Long, ByVal fWait As Boolean, ByVal lpdwFlags As Long) As Boolean
  578.  
  579. Type WSABUF
  580.   dwBufferLen As Long
  581.   lpBuffer    As Long
  582. End Type
  583.  
  584. Type QUALITYOFSERVICE
  585.   SendingFlowspec   As FLOWSPEC
  586.   ReceivingFlowspec As FLOWSPEC
  587.   ProviderSpecific  As WSABUF
  588. End Type
  589.  
  590. Declare Function WSAGetQOSByName Lib "ws2_32" (ByVal hSocket As Long, lpQOSName As Long, lpQOS As QUALITYOFSERVICE)
  591.  
  592. Declare Function WSAGetServiceClassInfo Lib "ws2_32" Alias "WSAGetServiceClassInfoA" (lpProviderId As CLSID, lpServiceClassId As CLSID, ByVal lpdwBufferLength As Long, ByVal lpServiceClassInfo As Long) As Integer
  593.  
  594. Declare Function WSAGetServiceClassNameByClassId Lib "ws2_32" Alias "WSAGetServiceClassNameByClassIdA" (lpServiceClassId As CLSID, ByVal lpszServiceClassName As String, ByVal lpdwBufferLength As Integer) As Integer
  595.  
  596. Declare Function WSAHtonl Lib "ws2_32" (ByVal hSocket As Long, ByVal dwHostLong As Long, dwNetLong As Long) As Integer
  597.  
  598. Declare Function WSAHtons Lib "ws2_32" (ByVal hSocket As Long, ByVal iHostShort As Integer, lpNetShort As Integer) As Integer
  599.  
  600. Type WSAServiceClassInfo
  601.   lpServiceClassId      As CLSID
  602.   lpszServiceClassName  As String
  603.   dwCount               As Long
  604.   lpClassInfos          As Long
  605. End Type
  606.  
  607. Declare Function WSAInstallServiceClass Lib "ws2_32" Alias "WSAInstallServiceClassA" (lpServiceClassInfo As WSAServiceClassInfo)
  608.  
  609. Declare Function WSAIoctl Lib "ws2_32" (ByVal hSocket As Long, ByVal dwIoControlCode As Long, ByVal lpvInBuffer As Long, ByVal cbInBuffer As Long, ByVal lpvOUTBuffer As Long, ByVal bOUTBuffer As Long, lpcbBytesReturned As Long, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long)
  610.  
  611. Declare Function WSAJoinLeaf Lib "ws2_32" (ByVal hSocket As Long, lpSckName As SOCKADDR, ByVal iSckNameLen As Integer, lpCallerData As WSABUF, lpCalleeData As WSABUF, lpSQOS As FLOWSPEC, lpGQOS As FLOWSPEC, ByVal dwFlags As Long) As Long
  612.  
  613. Enum WSAEcomparator
  614.   COMP_EQUAL = 0
  615.   COMP_NOTLESS = 1
  616. End Enum
  617.  
  618. Type WSAVersion
  619.   dwVersion As Long
  620.   ecHow     As WSAEcomparator
  621. End Type
  622.  
  623. Type AFPROTOCOLS
  624.   iAddressFamily  As Integer
  625.   iProtocol       As Integer
  626. End Type
  627.  
  628. Type SOCKET_ADDRESS
  629.   lpSockaddr      As Long
  630.   iSockaddrLength As Long
  631. End Type
  632.  
  633. Type WSAQuerySet
  634.   dwSize                  As Long
  635.   lpszServiceInstanceName As String
  636.   lpServiceClassId        As CLSID
  637.   lpVersion               As WSAVersion
  638.   lpszComment             As String
  639.   dwNameSpace             As Long
  640.   lpNSProviderId          As CLSID
  641.   lpszContext             As String
  642.   dwNumberOfProtocols     As Long
  643.   lpafpProtocols          As Long
  644.   lpszQueryString         As String
  645.   dwNumberOfCsAddrs       As Long
  646.   lpcsaBuffer             As CSADDR_INFO
  647.   dwOutputFlags           As Long
  648.   lpBlob                  As BLOB
  649. End Type
  650.  
  651. Declare Function WSALookupServiceBegin Lib "ws2_32" Alias "WSALookupServiceBeginA" (ByVal lpqsRestrictions As WSAQuerySet, ByVal dwControlFlags As SearchControlFlags, lphLookup As Long) As Integer
  652.  
  653. Declare Function WSALookupServiceEnd Lib "ws2_32" (ByVal hLookup As Long) As Integer
  654.  
  655. Declare Function WSALookupServiceNext Lib "ws2_32" Alias "WSALookupServiceNextA" (ByVal hLookup As Long, ByVal dwControlFlags As SearchControlFlags, lpdwBufferLength As Long, lpqsResults As WSAQuerySet) As Integer
  656.  
  657. Declare Function WSANtohl Lib "ws2_32" (ByVal hSocket As Long, ByVal lpNetLong As Long, lpHostLong As Long) As Integer
  658.  
  659. Declare Function WSANtohs Lib "ws2_32" (ByVal hSocket As Long, ByVal lpNetShort As Integer, lpHostShort As Integer) As Integer
  660.  
  661. Declare Function WSAProviderConfigChange Lib "ws2_32" (ByVal lpNotificationHandle As Long, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long) As Integer
  662.  
  663. Declare Function WSARecvEx Lib "ws2_32" (ByVal hSocket As Long, ByVal lpBuffers As Long, ByVal dwBufferCount As Long, lpNumberOfBytesRecvd As Long, lpFlags As Long, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long) As Integer
  664.  
  665. Declare Function WSARecvDisconnect Lib "ws2_32" (ByVal hSocket As Long, lpInboundDisconnectData As WSABUF) As Integer
  666.  
  667. Declare Function WSARecvFrom Lib "ws2_32" (ByVal hSocket As Long, ByVal lpBuffers As Long, ByVal dwBufferCount As Long, lpNumberOfBytesRecvd As Long, lpFlags As Long, lpFrom As SOCKADDR, lpFromlen As Integer, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long) As Integer
  668.  
  669. Declare Function WSARemoveServiceClass Lib "ws2_32" (lpServiceClassId As CLSID) As Integer
  670.  
  671. Declare Function WSAResetEvent Lib "ws2_32" (ByVal hEvent As Long) As Boolean
  672.  
  673. Declare Function WSASend Lib "ws2_32" (ByVal hSocket As Long, ByVal lpBuffers As Long, ByVal dwBufferCount As Long, lpNumberOfBytesSent As Long, ByVal dwFlags As Long, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long) As Integer
  674.  
  675. Declare Function WSASendDisconnect Lib "ws2_32" (ByVal hSocket As Long, boundDisconnectData As WSABUF) As Integer
  676.  
  677. Declare Function WSASendTo Lib "ws2_32" (ByVal hSocket As Long, ByVal lpBuffers As Long, ByVal dwBufferCount As Long, lpNumberOfBytesSent As Long, ByVal dwFlags As Long, lpTo As SOCKADDR, ByVal iToLen As Integer, lpOverlapped As WSAOVERLAPPED, ByVal lpCompletionROUTINE As Long) As Integer
  678.  
  679. Declare Function WSASetEvent Lib "ws2_32" (ByVal hEvent As Long) As Boolean
  680. Declare Sub WSASetLastError Lib "ws2_32" (ByVal iError As Integer)
  681.  
  682. Enum WSAESETSERVICEOP
  683.   RNRSERVICE_REGISTER = 0
  684.   RNRSERVICE_DEREGISTER = 1
  685.   RNRSERVICE_DELETE = 2
  686. End Enum
  687.  
  688. Declare Function WSASetService Lib "ws2_32" Alias "WSASetServiceA" (lpqsRegInfo As WSAQuerySet, essOperation As WSAESETSERVICEOP, ByVal dwControlFlags As Long) As Integer
  689.  
  690. Declare Function WSASocket Lib "ws2_32" Alias "WSASocketA" (ByVal iAddressFamily As Integer, ByVal iType As Integer, ByVal iProtocol As Integer, lpProtocolInfo As WSAPROTOCOL_INFO, ByVal lpGroup As Long, ByVal dwFlags As Long) As Long
  691.  
  692. Declare Function WSAStartup Lib "ws2_32" (ByVal wVersionRequired As Long, lpWSAData As WSADATA) As Long
  693.  
  694. Declare Function WSAStringToAddress Lib "ws2_32" (ByVal AddressString As String, ByVal AddressFamily As Integer, lpProtocolInfo As WSAPROTOCOL_INFO, lpAddress As SOCKADDR, lpAddressLength As Integer) As Integer
  695.  
  696. Public SockLastError As Long
  697.  
  698. Function sckhibyte(ByVal wParam As Integer)
  699.   sckhibyte = (wParam \ &H100) And &HFF&
  700. End Function
  701.  
  702. Function scklobyte(ByVal wParam As Integer)
  703.   scklobyte = wParam And &HFF&
  704. End Function
  705.  
  706. Property Get LocalHostName() As String
  707.      
  708.       Dim sStr As String * 256, lStr&
  709.       Dim r&
  710.      
  711.   r = gethostname(sStr, 256)
  712.   SockLastError = WSAGetLastError()
  713.  
  714.   LocalHostName = Trim(Replace(sStr, vbNullChar, vbNullString))
  715. End Property
  716.  
  717. Property Get LocalHostIP() As String
  718.  
  719.    Dim sHostName$, pHostent&
  720.    Dim pHost As HOSTENT
  721.    Dim hIPAddress&, sIPAddress$
  722.    Dim abIPAddress() As Byte
  723.    Dim i%
  724.  
  725.  
  726.   sHostName = LocalHostName
  727.   pHostent = gethostbyname(sHostName)
  728.   SockLastError = WSAGetLastError()
  729.  
  730.   If pHostent = 0 Then Exit Property
  731.  
  732.   CopyMemory ByVal pHost, ByVal pHostent, ByVal LenB(pHost)
  733.   CopyMemory hIPAddress, ByVal pHost.h_addr_list, ByVal 4&
  734.  
  735.   ReDim abIPAddress(1 To pHost.h_length)
  736.   CopyMemory abIPAddress(1), ByVal hIPAddress, ByVal pHost.h_length
  737.  
  738.   For i = 1 To pHost.h_length
  739.     sIPAddress = sIPAddress & abIPAddress(i) & "."
  740.   Next
  741.  
  742.   LocalHostIP = Left$(sIPAddress, Len(sIPAddress) - 1)
  743.  
  744. End Property
  745.  
  746. Sub SocketsInitialize()
  747.       Dim WSAD As WSADATA
  748.       Dim iReturn As Integer
  749.       Dim sLowByte As String, sHighByte As String, sMsg As String
  750.  
  751.     iReturn = WSAStartup(WS_VERSION_REQD, WSAD)
  752.     SockLastError = WSAGetLastError()
  753.  
  754.     If iReturn <> 0 Then
  755.       Exit Sub
  756.     End If
  757.  
  758.     If LoByte(WSAD.wversion) < WS_VERSION_MAJOR Or _
  759.       (LoByte(WSAD.wversion) = WS_VERSION_MAJOR And _
  760.         HiByte(WSAD.wversion) < WS_VERSION_MINOR) Then
  761.        
  762.         Exit Sub
  763.     End If
  764.  
  765.     If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
  766.       Exit Sub
  767.     End If
  768.  
  769. End Sub
  770.  
  771. Function SocketsCleanup() As Long
  772.   SocketsCleanup = WSACleanup()
  773. End Function
  774.  
  775. Function CreateSocket(ByVal SockType As SockTypes, Optional ByVal Protocol As SockProtocols = IPPROTO_TCP) As Long
  776.   CreateSocket = socket(AF_NETBIOS, SockType, Protocol)
  777.   SockLastError = WSAGetLastError
  778. End Function
  779.  
  780. Function DestroySocket(hSocket As Long) As Boolean
  781.   DestroySocket = (closesocket(hSocket) = 0)
  782.   SockLastError = WSAGetLastError
  783. End Function
  784.  
  785. Function GetSckName(hSocket As Long) As String
  786.       Dim sName$
  787.       Dim pSckAdd As SOCKADDR, lpAdd&
  788.       Dim r&
  789.  
  790.   r = GetSockNameA(hSocket, lpAdd, LenB(pSckAdd))
  791.   SockLastError = WSAGetLastError
  792.  
  793.   CopyMemory ByVal pSckAdd, ByVal lpAdd, ByVal LenB(pSckAdd)
  794.  
  795.   GetSckName = Trim(Replace(pSckAdd.sa_data, vbNullChar, vbNullString))
  796.  
  797. End Function
  798.  
Ojala les guste chao.
El pasado son solo recuerdos, el futuro son solo sueños

Cyclop

  • Miembro MUY activo
  • ***
  • Mensajes: 323
    • Ver Perfil
    • http://www.geocities.com/icotext/spanish/
Re: Api Winsock
« Respuesta #1 en: Jueves 9 de Junio de 2005, 22:04 »
0
Yo encontre uno mejor, trabaja con los apis pero te crea un control personalizado (usercontrol) con el WinSock.Ocx, maneja los mismos metodos y eventos que el .OCX. despues lo subo.

Salu2

Cyclopz
Icotext Evolution v0.5 para los amantes del ASCII Art
http]

RadicalEd

  • Moderador
  • ******
  • Mensajes: 2430
  • Nacionalidad: co
    • Ver Perfil
Re: Api Winsock
« Respuesta #2 en: Jueves 9 de Junio de 2005, 22:10 »
0
Cita de: "Cyclop"
Yo encontre uno mejor, trabaja con los apis pero te crea un control personalizado (usercontrol) con el WinSock.Ocx, maneja los mismos metodos y eventos que el .OCX. despues lo subo.

Salu2

Cyclopz
Pero es que lo bueno es no cargar controles, para hacer un poquito mas portable el programa.
El pasado son solo recuerdos, el futuro son solo sueños

Kev

  • Miembro HIPER activo
  • ****
  • Mensajes: 654
    • Ver Perfil
Re: Api Winsock
« Respuesta #3 en: Viernes 10 de Junio de 2005, 00:12 »
0
Bueno yo pienso que mas que armar controles, o hacer mas portable el programa esta el performance de la aplicacion porque por ejemplo el control Winsock es pesado por tal motivo la mayoria de la gente recurre a usar su API y asi trabajar a mas bajo nivel y hacer mas eficiente un programa, por ejemplo hacer correr unos... 4 o mas winsocks y veran lo que les digo.

Hay mucho codigo disponible en la red para trabajar con sockets a bajo nivel y superar las funciones del winsock, aca les paso una pagina que tiene bastante info al respecto

VB y sockets

En este aspecto .NET tiene unas clases bastante trabajadas y ya no es necesario batirse con tanto codigo, es una maravilla y es muy eficiente.

Salu2
 :comp:  :hola:
La teoria es asesinada tarde o temprano por la experiencia
Albert Einstein
Kev - 3 DCE
-----------------------------------------------------
Articulos:
Convertir texto a imagen en ASP.NET
Trabajando con el Global.asax