• Domingo 22 de Diciembre de 2024, 16:47

Autor Tema:  Conexion A Servidor Remoto  (Leído 2397 veces)

desarrollo

  • Miembro activo
  • **
  • Mensajes: 74
    • Ver Perfil
Conexion A Servidor Remoto
« en: Lunes 17 de Enero de 2005, 19:27 »
0
Hola a todos tengo una inquietud, debere instalar una aplicacion en una pc k que se encuentra fuera del local donde esta mi servidor por lo k he leido se k puedo lograr la conexion con el servidor mediente el ip de este pero realmente no estoy muy segura de lo k debere hacer me podrian proporcionar informacion al respecto

Muchas gracias de Antemano.

RadicalEd

  • Moderador
  • ******
  • Mensajes: 2430
  • Nacionalidad: co
    • Ver Perfil
Re: Conexion A Servidor Remoto
« Respuesta #1 en: Lunes 17 de Enero de 2005, 20:12 »
0
Si eres una dura para la programacion con Api's, por medio de estas lo puedes hacer, pero sino hay un control llamado Winsock, con este puedes hacer conexiones a otros PC's.
Ojala te sirva.
Chao
El pasado son solo recuerdos, el futuro son solo sueños

desarrollo

  • Miembro activo
  • **
  • Mensajes: 74
    • Ver Perfil
Re: Conexion A Servidor Remoto
« Respuesta #2 en: Lunes 17 de Enero de 2005, 21:41 »
0
Podrias explicarme acerca de como hacerlo con Api's  el winsock no es lo k necesito

RadicalEd

  • Moderador
  • ******
  • Mensajes: 2430
  • Nacionalidad: co
    • Ver Perfil
Re: Conexion A Servidor Remoto
« Respuesta #3 en: Lunes 17 de Enero de 2005, 21:59 »
0
Te recomiendo que te descargues este programa, enseña muy como manejar las api's de windows, por lo bruto yo no sabo como manejar las de conexion a PC's, pero aqui te dejo un ejemplo de la misma pagina donde descargas el programa.
Código: Text
  1.  
  2. 'This project needs a TextBox
  3. '-> (Name)=Text1
  4. '-> MultiLine=True
  5. 'in a form
  6. Private Sub Form_Load()
  7.     'KPD-Team 2000
  8.     'URL: http://www.allapi.net/
  9.     'E-Mail: KPDTeam@Allapi.net
  10.     Dim sSave As String
  11.     Me.AutoRedraw = True
  12.     Set Obj = Me.Text1
  13.     'Start subclassing
  14.     HookForm Me
  15.     'create a new winsock session
  16.     StartWinsock sSave
  17.     'show the winsock version on this form
  18.     If InStr(1, sSave, Chr$(0)) > 0 Then sSave = Left$(sSave, InStr(1, sSave, Chr$(0)) - 1)
  19.     Me.Print sSave
  20.     'connect to Microsoft.com
  21.     lSocket = ConnectSock("www.microsoft.com", 80, 0, Me.hwnd, False)
  22. End Sub
  23. Private Sub Form_Unload(Cancel As Integer)
  24.     'close our connection to microsoft.com
  25.     closesocket lSocket
  26.     'end winsock session
  27.     EndWinsock
  28.     'stop subclassing
  29.     UnHookForm Me
  30. End Sub
  31. 'in a module
  32. Public Const AF_INET = 2
  33. Public Const INVALID_SOCKET = -1
  34. Public Const SOCKET_ERROR = -1
  35. Public Const FD_READ = &H1&
  36. Public Const FD_WRITE = &H2&
  37. Public Const FD_CONNECT = &H10&
  38. Public Const FD_CLOSE = &H20&
  39. Public Const PF_INET = 2
  40. Public Const SOCK_STREAM = 1
  41. Public Const IPPROTO_TCP = 6
  42. Public Const GWL_WNDPROC = (-4)
  43. Public Const WINSOCKMSG = 1025
  44. Public Const WSA_DESCRIPTIONLEN = 256
  45. Public Const WSA_DescriptionSize = WSA_DESCRIPTIONLEN + 1
  46. Public Const WSA_SYS_STATUS_LEN = 128
  47. Public Const WSA_SysStatusSize = WSA_SYS_STATUS_LEN + 1
  48. Public Const INADDR_NONE = &HFFFF
  49. Public Const SOL_SOCKET = &HFFFF&
  50. Public Const SO_LINGER = &H80&
  51. Public Const hostent_size = 16
  52. Public Const sockaddr_size = 16
  53. Type WSADataType
  54.     wVersion As Integer
  55.     wHighVersion As Integer
  56.     szDescription As String * WSA_DescriptionSize
  57.     szSystemStatus As String * WSA_SysStatusSize
  58.     iMaxSockets As Integer
  59.     iMaxUdpDg As Integer
  60.     lpVendorInfo As Long
  61. End Type
  62. Type HostEnt
  63.     h_name As Long
  64.     h_aliases As Long
  65.     h_addrtype As Integer
  66.     h_length As Integer
  67.     h_addr_list As Long
  68. End Type
  69. Type sockaddr
  70.     sin_family As Integer
  71.     sin_port As Integer
  72.     sin_addr As Long
  73.     sin_zero As String * 8
  74. End Type
  75. Type LingerType
  76.     l_onoff As Integer
  77.     l_linger As Integer
  78. End Type
  79. Public Declare Function setsockopt Lib "wsock32.dll" (ByVal s As Long, ByVal Level As Long, ByVal optname As Long, optval As Any, ByVal optlen As Long) As Long
  80. Public Declare Function getsockopt Lib "wsock32.dll" (ByVal s As Long, ByVal Level As Long, ByVal optname As Long, optval As Any, optlen As Long) As Long
  81. Public Declare Function WSAGetLastError Lib "wsock32.dll" () As Long
  82. Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  83. Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  84. Public Declare Function WSAIsBlocking Lib "wsock32.dll" () As Long
  85. Public Declare Function WSACleanup Lib "wsock32.dll" () As Long
  86. Public Declare Function Send Lib "wsock32.dll" Alias "send" (ByVal s As Long, buf As Any, ByVal buflen As Long, ByVal flags As Long) As Long
  87. Public Declare Function recv Lib "wsock32.dll" (ByVal s As Long, buf As Any, ByVal buflen As Long, ByVal flags As Long) As Long
  88. Public Declare Function WSAStartup Lib "wsock32.dll" (ByVal wVR As Long, lpWSAD As WSADataType) As Long
  89. Public Declare Function htons Lib "wsock32.dll" (ByVal hostshort As Long) As Integer
  90. Public Declare Function ntohs Lib "wsock32.dll" (ByVal netshort As Long) As Integer
  91. Public Declare Function socket Lib "wsock32.dll" (ByVal af As Long, ByVal s_type As Long, ByVal protocol As Long) As Long
  92. Public Declare Function closesocket Lib "wsock32.dll" (ByVal s As Long) As Long
  93. Public Declare Function Connect Lib "wsock32.dll" Alias "connect" (ByVal s As Long, addr As sockaddr, ByVal namelen As Long) As Long
  94. Public Declare Function WSAAsyncSelect Lib "wsock32.dll" (ByVal s As Long, ByVal hwnd As Long, ByVal wMsg As Long, ByVal lEvent As Long) As Long
  95. Public Declare Function inet_addr Lib "wsock32.dll" (ByVal cp As String) As Long
  96. Public Declare Function gethostbyname Lib "wsock32.dll" (ByVal host_name As String) As Long
  97. Public Declare Sub MemCopy Lib "kernel32" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb&)
  98. Public Declare Function inet_ntoa Lib "wsock32.dll" (ByVal inn As Long) As Long
  99. Public Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
  100. Public Declare Function WSACancelBlockingCall Lib "wsock32.dll" () As Long
  101. Public saZero As sockaddr
  102. Public WSAStartedUp As Boolean, Obj As TextBox
  103. Public PrevProc As Long, lSocket As Long
  104. 'subclassing functions
  105. 'for more information about subclassing,
  106. 'check out the subclassing tutorial at http://www.allapi.net/
  107. Public Sub HookForm(F As Form)
  108.     PrevProc = SetWindowLong(F.hwnd, GWL_WNDPROC, AddressOf WindowProc)
  109. End Sub
  110. Public Sub UnHookForm(F As Form)
  111.     If PrevProc <> 0 Then
  112.         SetWindowLong F.hwnd, GWL_WNDPROC, PrevProc
  113.         PrevProc = 0
  114.     End If
  115. End Sub
  116. Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  117.     If uMsg = WINSOCKMSG Then
  118.         ProcessMessage wParam, lParam
  119.     Else
  120.         WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam)
  121.     End If
  122. End Function
  123. 'our Winsock-message handler
  124. Public Sub ProcessMessage(ByVal lFromSocket As Long, ByVal lParam As Long)
  125.     Dim X As Long, ReadBuffer(1 To 1024) As Byte, strCommand As String
  126.     Select Case lParam
  127.         Case FD_CONNECT 'we are connected to microsoft.com
  128.         Case FD_WRITE 'we can write to our connection
  129.             'this is a part of the HTTP protocol
  130.             'for more information about this protocol, visit http://www.w3c.org/
  131.             strCommand = "GET http://www.microsoft.com/ HTTP/1.0" + vbCrLf
  132.             strcomand = strCommand + "Pragma: no-cache" + vbCrLf
  133.             strCommand = strCommand + "Accept: */*" + vbCrLf
  134.             strCommand = strCommand + "Accept: text/html" + vbCrLf + vbCrLf
  135.             'send the data to our microsoft.com-connection
  136.             SendData lFromSocket, strCommand
  137.         Case FD_READ 'we have data waiting to be processed
  138.             'start reading the data
  139.             Do
  140.                 X = recv(lFromSocket, ReadBuffer(1), 1024, 0)
  141.                 If X > 0 Then
  142.                     Obj.Text = Obj.Text + Left$(StrConv(ReadBuffer, vbUnicode), X)
  143.                 End If
  144.                 If X <> 1024 Then Exit Do
  145.             Loop
  146.         Case FD_CLOSE 'the connection with microsoft.com is closed
  147.     End Select
  148. End Sub
  149. 'the following functions are standard WinSock functions
  150. 'from the wsksock.bas-file
  151. Public Function StartWinsock(sDescription As String) As Boolean
  152.     Dim StartupData As WSADataType
  153.     If Not WSAStartedUp Then
  154.         If Not WSAStartup(&H101, StartupData) Then
  155.             WSAStartedUp = True
  156.             sDescription = StartupData.szDescription
  157.         Else
  158.             WSAStartedUp = False
  159.         End If
  160.     End If
  161.     StartWinsock = WSAStartedUp
  162. End Function
  163. Sub EndWinsock()
  164.     Dim Ret&
  165.     If WSAIsBlocking() Then
  166.         Ret = WSACancelBlockingCall()
  167.     End If
  168.     Ret = WSACleanup()
  169.     WSAStartedUp = False
  170. End Sub
  171. Public Function SendData(ByVal s&, vMessage As Variant) As Long
  172.     Dim TheMsg() As Byte, sTemp$
  173.     TheMsg = ""
  174.     Select Case VarType(vMessage)
  175.         Case 8209   'byte array
  176.             sTemp = vMessage
  177.             TheMsg = sTemp
  178.         Case 8      'string, if we recieve a string, its assumed we are linemode
  179.             sTemp = StrConv(vMessage, vbFromUnicode)
  180.         Case Else
  181.             sTemp = CStr(vMessage)
  182.             sTemp = StrConv(vMessage, vbFromUnicode)
  183.     End Select
  184.     TheMsg = sTemp
  185.     If UBound(TheMsg) > -1 Then
  186.         SendData = Send(s, TheMsg(0), (UBound(TheMsg) - LBound(TheMsg) + 1), 0)
  187.     End If
  188. End Function
  189. Function ConnectSock(ByVal Host$, ByVal Port&, retIpPort$, ByVal HWndToMsg&, ByVal Async%) As Long
  190.     Dim s&, SelectOps&, Dummy&
  191.     Dim sockin As sockaddr
  192.     SockReadBuffer$ = ""
  193.     sockin = saZero
  194.     sockin.sin_family = AF_INET
  195.     sockin.sin_port = htons(Port)
  196.     If sockin.sin_port = INVALID_SOCKET Then
  197.         ConnectSock = INVALID_SOCKET
  198.         Exit Function
  199.     End If
  200.  
  201.     sockin.sin_addr = GetHostByNameAlias(Host$)
  202.  
  203.     If sockin.sin_addr = INADDR_NONE Then
  204.         ConnectSock = INVALID_SOCKET
  205.         Exit Function
  206.     End If
  207.     retIpPort$ = getascip$(sockin.sin_addr) & ":" & ntohs(sockin.sin_port)
  208.  
  209.     s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)
  210.     If s < 0 Then
  211.         ConnectSock = INVALID_SOCKET
  212.         Exit Function
  213.     End If
  214.     If SetSockLinger(s, 1, 0) = SOCKET_ERROR Then
  215.         If s > 0 Then
  216.             Dummy = closesocket(s)
  217.         End If
  218.         ConnectSock = INVALID_SOCKET
  219.         Exit Function
  220.     End If
  221.     If Not Async Then
  222.         If Connect(s, sockin, sockaddr_size) <> 0 Then
  223.             If s > 0 Then
  224.                 Dummy = closesocket(s)
  225.             End If
  226.             ConnectSock = INVALID_SOCKET
  227.             Exit Function
  228.         End If
  229.         SelectOps = FD_READ Or FD_WRITE Or FD_CONNECT Or FD_CLOSE
  230.         If WSAAsyncSelect(s, HWndToMsg, ByVal 1025, ByVal SelectOps) Then
  231.             If s > 0 Then
  232.                 Dummy = closesocket(s)
  233.             End If
  234.             ConnectSock = INVALID_SOCKET
  235.             Exit Function
  236.         End If
  237.     Else
  238.         SelectOps = FD_READ Or FD_WRITE Or FD_CONNECT Or FD_CLOSE
  239.         If WSAAsyncSelect(s, HWndToMsg, ByVal 1025, ByVal SelectOps) Then
  240.             If s > 0 Then
  241.                 Dummy = closesocket(s)
  242.             End If
  243.             ConnectSock = INVALID_SOCKET
  244.             Exit Function
  245.         End If
  246.         If Connect(s, sockin, sockaddr_size) <> -1 Then
  247.             If s > 0 Then
  248.                 Dummy = closesocket(s)
  249.             End If
  250.             ConnectSock = INVALID_SOCKET
  251.             Exit Function
  252.         End If
  253.     End If
  254.     ConnectSock = s
  255. End Function
  256. Function GetHostByNameAlias(ByVal hostname$) As Long
  257.     On Error Resume Next
  258.     Dim phe&
  259.     Dim heDestHost As HostEnt
  260.     Dim addrList&
  261.     Dim retIP&
  262.     retIP = inet_addr(hostname)
  263.     If retIP = INADDR_NONE Then
  264.         phe = gethostbyname(hostname)
  265.         If phe <> 0 Then
  266.             MemCopy heDestHost, ByVal phe, hostent_size
  267.             MemCopy addrList, ByVal heDestHost.h_addr_list, 4
  268.             MemCopy retIP, ByVal addrList, heDestHost.h_length
  269.         Else
  270.             retIP = INADDR_NONE
  271.         End If
  272.     End If
  273.     GetHostByNameAlias = retIP
  274.     If Err Then GetHostByNameAlias = INADDR_NONE
  275. End Function
  276. Function getascip(ByVal inn As Long) As String
  277.     On Error Resume Next
  278.     Dim lpStr&
  279.     Dim nStr&
  280.     Dim retString$
  281.     retString = String(32, 0)
  282.     lpStr = inet_ntoa(inn)
  283.     If lpStr = 0 Then
  284.         getascip = "255.255.255.255"
  285.         Exit Function
  286.     End If
  287.     nStr = lstrlen(lpStr)
  288.     If nStr > 32 Then nStr = 32
  289.     MemCopy ByVal retString, ByVal lpStr, nStr
  290.     retString = Left(retString, nStr)
  291.     getascip = retString
  292.     If Err Then getascip = "255.255.255.255"
  293. End Function
  294. Public Function SetSockLinger(ByVal SockNum&, ByVal OnOff%, ByVal LingerTime%) As Long
  295.     Dim Linger As LingerType
  296.     Linger.l_onoff = OnOff
  297.     Linger.l_linger = LingerTime
  298.     If setsockopt(SockNum, SOL_SOCKET, SO_LINGER, Linger, 4) Then
  299.         Debug.Print "Error setting linger info: " & WSAGetLastError()
  300.         SetSockLinger = SOCKET_ERROR
  301.     Else
  302.         If getsockopt(SockNum, SOL_SOCKET, SO_LINGER, Linger, 4) Then
  303.             Debug.Print "Error getting linger info: " & WSAGetLastError()
  304.             SetSockLinger = SOCKET_ERROR
  305.         End If
  306.     End If
  307. End Function
  308.  
  309.  
Ojala te sirva.
Chao
El pasado son solo recuerdos, el futuro son solo sueños

RadicalEd

  • Moderador
  • ******
  • Mensajes: 2430
  • Nacionalidad: co
    • Ver Perfil
Re: Conexion A Servidor Remoto
« Respuesta #4 en: Lunes 17 de Enero de 2005, 22:59 »
0
Esta es como mas completa
Ojala te sirva.
Chao
El pasado son solo recuerdos, el futuro son solo sueños

desarrollo

  • Miembro activo
  • **
  • Mensajes: 74
    • Ver Perfil
Re: Conexion A Servidor Remoto
« Respuesta #5 en: Martes 18 de Enero de 2005, 14:49 »
0
Muchas gracias por los ejemplos