Visual Basic - winsock y sus errores ayuda!!!

Life is soft - evento anual de software empresarial
 
Vista:

winsock y sus errores ayuda!!!

Publicado por Alejandro (5 intervenciones) el 05/09/2005 05:06:30
Supongamos que mientras estoy usando mi aplicacion cliente servidor, en el pc que estoy usando el cliente se cae internet o el sistema, como podriamos hacer que el servidor detecte esto y se quede en modo listes o escucha nuevamente, es algo que realmente me tiene parado en mi trabajo si alguien tiene la solucion por favor responda, de antemano gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 14
Ha aumentado 1 puesto en Visual Basic (en relación al último mes)
Gráfica de Visual Basic

RE:winsock y sus errores ayuda!!!

Publicado por SuNcO (599 intervenciones) el 05/09/2005 05:41:36
Con este codigo puedes estar monitoreando si hay o no conexion a internet :

En el formulario :

Private Sub Command1_Click()
GetNetConnectString
End Sub

En un modulo :

Public Declare Function InternetGetConnectedState Lib "wininet" _
(ByRef dwflags As Long, _
ByVal dwReserved As Long) As Long

'Local system uses a modem to connect to the Internet.
Public Const INTERNET_CONNECTION_MODEM As Long = &H1

'Local system uses a LAN to connect to the Internet.
Public Const INTERNET_CONNECTION_LAN As Long = &H2

'Local system uses a proxy server to connect to the Internet.
Public Const INTERNET_CONNECTION_PROXY As Long = &H4

'No longer used.
Public Const INTERNET_CONNECTION_MODEM_BUSY As Long = &H8

Public Const INTERNET_RAS_INSTALLED As Long = &H10
Public Const INTERNET_CONNECTION_OFFLINE As Long = &H20
Public Const INTERNET_CONNECTION_CONFIGURED As Long = &H40

'InternetGetConnectedState wrapper functions
Public Function IsNetConnectViaLAN() As Boolean

Dim dwflags As Long

'pass an empty variable into which the API will
'return the flags associated with the connection
Call InternetGetConnectedState(dwflags, 0&)

'return True if the flags indicate a LAN connection
IsNetConnectViaLAN = dwflags And INTERNET_CONNECTION_LAN

End Function

Public Function IsNetConnectViaModem() As Boolean

Dim dwflags As Long

'pass an empty variable into which the API will
'return the flags associated with the connection
Call InternetGetConnectedState(dwflags, 0&)

'return True if the flags indicate a modem connection
IsNetConnectViaModem = dwflags And INTERNET_CONNECTION_MODEM

End Function

Public Function IsNetConnectViaProxy() As Boolean

Dim dwflags As Long

'pass an empty variable into which the API will
'return the flags associated with the connection
Call InternetGetConnectedState(dwflags, 0&)

'return True if the flags indicate a proxy connection
IsNetConnectViaProxy = dwflags And INTERNET_CONNECTION_PROXY

End Function

Public Function IsNetConnectOnline() As Boolean

'no flags needed here - the API returns True
'if there is a connection of any type
IsNetConnectOnline = InternetGetConnectedState(0&, 0&)

End Function

Public Function IsNetRASInstalled() As Boolean

Dim dwflags As Long

'pass an empty variable into which the API will
'return the flags associated with the connection
Call InternetGetConnectedState(dwflags, 0&)

'return True if the flags include RAS installed
IsNetRASInstalled = dwflags And INTERNET_RAS_INSTALLED

End Function

Public Function GetNetConnectString() As String

Dim dwflags As Long
Dim msg As String

'build a string for display
If InternetGetConnectedState(dwflags, 0&) Then

If dwflags And INTERNET_CONNECTION_CONFIGURED Then
msg = msg & "Si hay conexion activa" & vbCrLf
End If

If dwflags And INTERNET_CONNECTION_LAN Then
msg = msg & "Hay conexion a travez de LAN"
End If

If dwflags And INTERNET_CONNECTION_PROXY Then
msg = msg & ", y utilizas proxy"
'Else: msg = msg & "."
End If

If dwflags And INTERNET_CONNECTION_MODEM Then
msg = msg & "La conexion es a travez de un modem" & vbCrLf
End If

If dwflags And INTERNET_CONNECTION_OFFLINE Then
msg = msg & "No hay conexion "
End If

If dwflags And INTERNET_CONNECTION_MODEM_BUSY Then
msg = msg & "El modem esta ocupado "
End If

Else

msg = "No hay conexion"

End If
MsgBox msg
GetNetConnectString = msg

End Function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:winsock y sus errores ayuda!!!

Publicado por Alejandro (5 intervenciones) el 06/09/2005 00:06:53
Gracias sunco, pero me refiero a cuando al cliente se cae, o se corta el internet en el pc del cliente, como el servidor puede saber este error, y que darse en listen. Por que por ejemplo el servidor siempre me manda texte, pero cuando se me cae la coneccion en el pc del cliente, el servidor falla y se cierra, eso es lo que quiero solucionar, de todas formas gracias sunco. :)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:winsock y sus errores ayuda!!!

Publicado por Esteban (1144 intervenciones) el 06/09/2005 05:09:07
Lo que necesitas ya está hecho, no debes poner nada de ese código que si bien es muy interesante y porqué no hasta útil, no deja de ser incómodo, la verdad el socket de servidor ya tiene un evento que detecta cuando un cliente se desconecta, ahí debes poner tu lógica para dejar una conexión lista para escuchar apenas quede liberada.

La parte difícil es cuando el cliente debe detectar que el servidor se desconectó, pero es solo una forma muy simple, y lo que necesitas es un timer que a cada X cantidad de tiempo envíe un "eco" al servidor, si el servidor responde es porque está conectado, sino, pues ya es de obvio terminar la conexión del lado del cliente para que conecte cuando el servidor esté activo nuevamente.

Yo tengo un gestor de licencias y ahí he probado todo eso que necesitas.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar