Winsock.localip

bidules - 14 mars 2001 à 16:32
damienvi Messages postés 5 Date d'inscription lundi 29 mars 2004 Statut Membre Dernière intervention 1 avril 2004 - 1 avril 2004 à 21:17
j'ai creé un petit pgrm, qui donne mon adresse ip, tres simple genre ( avec un bouton)

sub command1_click
label1.caption=winsock.localip
enb sub

quand j'ouvre ce pgrm et que j'appui sur le bouton j'obtient mon ip par defaut (carte reseaux) et ensuite qd je me connect a internet et que j'appui de nouveau sur le bouton l'ip ne change pas!
par contre si j'ouvre le pgrm apres m'etre connecté j'obtient bien un ip internet.
pourquoi? et comment faire pour lors de l'appui sur le bouton le bon ip s'affiche?

merci

4 réponses

Yuckz Messages postés 6 Date d'inscription samedi 5 janvier 2002 Statut Membre Dernière intervention 5 mars 2003
20 déc. 2002 à 20:04
je cherche aussi la solution a ce probleme !
S'il vous plaisssss....
0
Yuckz Messages postés 6 Date d'inscription samedi 5 janvier 2002 Statut Membre Dernière intervention 5 mars 2003
20 déc. 2002 à 20:19
solution temporaire :
unload me
load me
me.visible = true
text1 = winsock1.localip
0
Yuckz Messages postés 6 Date d'inscription samedi 5 janvier 2002 Statut Membre Dernière intervention 5 mars 2003
23 déc. 2002 à 12:21
Un type ( dont j'ai oublier le nom ) avait déposé une source qui fesais NetStat. Si on le reprend en virant ce qu'on a pas besoin sa donne :

Private Type MIB_TCPROW
dwState As Long
dwLocalAddr As Long
dwLocalPort As Long
dwRemoteAddr As Long
dwRemotePort As Long
End Type
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(dst As Any, _
src As Any, _
ByVal bcount As Long)
Private Declare Function GetTcpTable Lib "iphlpapi.dll" _
(ByRef pTcpTable As Any, _
ByRef pdwSize As Long, _
ByVal bOrder As Long) As Long
Private Declare Function inet_ntoa Lib "WSOCK32" _
(ByVal addr As Long) As Long
Private Declare Function lstrlenA Lib "kernel32" _
(ByVal Ptr As Any) As Long
Private Declare Function lstrcpyA Lib "kernel32" _
(ByVal RetVal As String, ByVal Ptr As Long) As Long
Public Function GetStrFromPtrA(ByVal lpszA As Long) As String
GetStrFromPtrA = String$(lstrlenA(ByVal lpszA), 0)
Call lstrcpyA(ByVal GetStrFromPtrA, ByVal lpszA)
End Function

Public Function GetInetStrFromPtr(Address As Long) As String
GetInetStrFromPtr = GetStrFromPtrA(inet_ntoa(Address))
End Function

Private Sub Command1_Click()
Dim TcpRow As MIB_TCPROW
Dim buff() As Byte
Dim cbRequired As Long
Dim nStructSize As Long
Dim nRows As Long
Dim cnt As Long

Call GetTcpTable(ByVal 0&, cbRequired, 1)
If cbRequired > 0 Then
ReDim buff(0 To cbRequired - 1) As Byte
If GetTcpTable(buff(0), cbRequired, 1) = ERROR_SUCCESS Then
nStructSize = LenB(TcpRow)
CopyMemory nRows, buff(0), 4
For cnt = 1 To nRows
CopyMemory TcpRow, buff(4 + (cnt - 1) * nStructSize), nStructSize
Next cnt
End If
End If
With TcpRow
text1.text = GetInetStrFromPtr(.dwLocalAddr)
End With
End sub
0
damienvi Messages postés 5 Date d'inscription lundi 29 mars 2004 Statut Membre Dernière intervention 1 avril 2004
1 avril 2004 à 21:17
Bonjour,

Je pose le décor : je veux faire de la communication entre un PC et un automate sous une couche TCP IP.

Pour ce faire, j'utilise l'API de windows (wsock32.dll) car je ne veux pas utiliser le contrôle winsock OCX, j'ai bien compris qu'il fallait :

1) initialiser la dll avec
Declare Function WSAStartup Lib "wsock32" _
(ByVal wVersionRequired As Integer, _
wsData As WSA_DATA) As Long

2) créer le socket avec
Declare Function Socket Lib "wsock32.dll" Alias "socket" _
(ByVal afinet As Integer, _
ByVal socktype As Integer, _
ByVal protocol As Integer) As Long

3) connecter le socket avec
Declare Function connect Lib "wsock32" _
(ByVal sock As Long, _
name As SOCK_ADDR, _
ByVal namelen As Integer) As Long

4) Envoyer un message sur le pc distant avec
Declare Function send Lib "wsock32" _
(ByVal sock As Long, _
buffer As Any, _
ByVal length As Long, _
ByVal flags As Long) As Long

Mais c'est maintenant que ça se complique, car avec le "client" crée ci dessus, je voudrais créer un évènement lors d'une réception d'un message par le serveur sur lequel je suis connecté.
Je crois avoir compris (mais là, je suis moins sur) que :

1) on peut analyser les évènemtns qui affectent un socket avec :
Declare Function WSAAsyncSelect Lib "wsock32.dll" _
(ByVal sock As Long, _
ByVal hwnd As Long, _
ByVal wMsg As Integer, _
ByVal lEvent As Long) As Integer
mais je ne sais pas trop m'en servir, à cause de hwnd.

2) on lit le message du socket reçu avec :
Declare Function recv Lib "wsock32" _
(ByVal sock As Long, _
buffer As Any, _
ByVal length As Long, _
ByVal flags As Long) As Long

Mon problème est donc le suivant :
comment avoir un évènement (du type "Data_arrival" du contrôle winsock) qui me réveille afin que je puisse utiliser ma fonction recv pour lire dans mon socket.

Merci pour le Share ;)
Je suis automaticien et pas informaticien, soyez indulgent ;)
0
Rejoignez-nous