Bonjour,
j'aurais besoin de créer un réseau LAN entre un serveur codé en VB6 et un client codé en Java.
coté matériel: il s'agit de 2 PC différents, Windows XP, reliés par un câble Ethernet. En utilisant uniquement Java, j'ai pu facilement monter le réseau, en créant un "socket client" sur le PC client et un "socket server" sur le PC serveur. Une fois la connexion effectuée, le client écoute le serveur et réceptionne ce que le serveur envoie. le serveur lui ne fait qu'envoyer des données.
Mon but est de transcrire la partie serveur en VB6 et de conserver la partie client en java. Le serveur VB6 sera utilisé pour envoyer des chaines de caractères au client java qui exécutera différentes procédures (= méthodes codées en java) selon le contenu de la chaine de caractères réceptionnée...
Le code VB6 sera écrit intégralement dans un module d'un activeX DLL, j'ai trouvé des exemples de codes dans l'api guide en recherchant "socket", ça ne m'a pas beaucoup éclairé.
Ensuite sur internet en tapant winSock j'ai trouve ce code :
Module 1
Module2:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 Option Explicit Public Const SOCKET_ERROR = -1 Public Const AF_INET = 2 Public Const PF_INET = AF_INET Public Const MAXGETHOSTSTRUCT = 1024 Public Const SOCK_STREAM = 1 Public Const MSG_PEEK = 2 Public Type SockAddr sin_family As Integer sin_port As Integer sin_addr As String * 4 sin_zero As String * 8 End Type Public Type T_WSA wVersion As Integer wHighVersion As Integer szDescription(0 To 255) As Byte szSystemStatus(0 To 128) As Byte iMaxSockets As Integer iMaxUdpDg As Integer lpVendorInfo As Long End Type Public WSAData As T_WSA Public Type Inet_Address Byte4 As String * 1 Byte3 As String * 1 Byte2 As String * 1 Byte1 As String * 1 End Type Public IPStruct As Inet_Address Public Type T_Host h_name As Long h_aliases As Long h_addrtype As Integer h_length As Integer h_addr_list As Long End Type ' KERNEL32.DLL funtions Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Dest As Any, Src As Any, ByVal cb&) ' WSOCK32.DLL functions Declare Function gethostbyaddr Lib "wsock32.dll" (addr As Long, ByVal addr_len As Long, ByVal addr_type As Long) As Long Declare Function inet_addr Lib "wsock32.dll" (ByVal addr As String) As Long Declare Function GetHostByName Lib "wsock32.dll" Alias "gethostbyname" (ByVal HostName As String) As Long Declare Function GetHostName Lib "wsock32.dll" Alias "gethostname" (ByVal HostName As String, HostLen As Long) As Long Declare Function WSAStartup Lib "wsock32.dll" (ByVal a As Long, b As T_WSA) As Long Declare Function WSACleanUp Lib "wsock32.dll" Alias "WSACleanup" () As Integer Declare Function Socket Lib "wsock32.dll" Alias "socket" (ByVal afinet As Integer, ByVal socktype As Integer, ByVal protocol As Integer) As Long Declare Function ConnectWinsock Lib "wsock32.dll" Alias "connect" (ByVal sock As Long, sockstruct As SockAddr, ByVal structlen As Integer) As Integer Declare Function send Lib "wsock32.dll" (ByVal sock As Long, ByVal msg As String, ByVal msglen As Integer, ByVal flag As Integer) As Integer Declare Function recv Lib "wsock32.dll" (ByVal sock As Long, ByVal msg As String, ByVal msglen As Integer, ByVal flag As Integer) As Integer Declare Function htonl Lib "wsock32.dll" (ByVal a As Long) As Long Declare Function ntohl Lib "wsock32.dll" (ByVal a As Long) As Long Declare Function htons Lib "wsock32.dll" (ByVal a As Integer) As Integer Declare Function ntohs Lib "wsock32.dll" (ByVal a As Integer) As Integer Declare Function closesocket Lib "wsock32.dll" (ByVal sn As Long) As Integer
mais je n'ai pas réussi a l'adapter pour créer mon "Socket server" en VB...Il me semble d'ailleurs que le code ci dessous correspond a un client plus qu'a un serveur, n'est-ce pas?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98 Function HostByName(sHost As String) As String Dim s As String Dim p As Long Dim Host As T_Host Dim ListAddress As Long Dim ListAddr As Long Dim Address As Long s = String(64, 0) sHost = sHost + Right(s, 64 - Len(sHost)) p = GetHostByName(sHost) If p = SOCKET_ERROR Then Exit Function Else If p <> 0 Then CopyMemory Host.h_name, ByVal p, Len(Host) ListAddress = Host.h_addr_list CopyMemory ListAddr, ByVal ListAddress, 4 CopyMemory Address, ByVal ListAddr, 4 HostByName = InetAddrLongToString(Address) Else HostByName = "No DNS Entry" End If End If End Function Private Function InetAddrStringToLong(Address As String) As Long InetAddrStringToLong = inet_addr(Address) End Function Private Function InetAddrLongToString(Address As Long) As String CopyMemory IPStruct, Address, 4 InetAddrLongToString = CStr(Asc(IPStruct.Byte4)) + "." + CStr(Asc(IPStruct.Byte3)) + "." + CStr(Asc(IPStruct.Byte2)) + "." + CStr(Asc(IPStruct.Byte1)) End Function Function HostByAddress(ByVal sAddress As String) As String Dim lAddress As Long Dim p As Long Dim HostName As String Dim Host As T_Host lAddress = inet_addr(sAddress) p = gethostbyaddr(lAddress, 4, PF_INET) If p <> 0 Then CopyMemory Host, ByVal p, Len(Host) HostName = String(256, 0) CopyMemory ByVal HostName, ByVal Host.h_name, 256 If HostName = "" Then HostByAddress = "Unable to Resolve Address" HostByAddress = Left(HostName, InStr(HostName, Chr(0)) - 1) Else HostByAddress = "No DNS Entry" End If End Function Private Function ResolveHost(sHost As String) As Long Dim lAddress As Long lAddress = InetAddrStringToLong(sHost) If lAddress = SOCKET_ERROR Then ResolveHost = inet_addr(HostByName(sHost)) Else ResolveHost = lAddress End If End Function Public Function WinsockConnect(ByVal m_RemoteHost As String, m_RemotePort As Long, iSocket As Long) As Boolean Dim sock As SockAddr Dim sRemoteIP As String Dim x As Long Dim bAddr(0 To 3) As Byte Dim i As Integer iSocket = Socket(AF_INET, SOCK_STREAM, 0) If iSocket < 1 Then WinsockConnect = False Exit Function End If sRemoteIP = "" sock.sin_family = AF_INET x = ResolveHost(m_RemoteHost) CopyMemory bAddr(0), x, 4 For i = 0 To 3 sRemoteIP = sRemoteIP & Chr(bAddr(i)) Next sock.sin_addr = sRemoteIP sock.sin_port = htons(m_RemotePort) sock.sin_zero = String(8, 0) If ConnectWinsock(iSocket, sock, Len(sock)) Then WinsockConnect = False Exit Function End If WinsockConnect = True End Function Public Sub WinsockInit() WSAStartup &H101, WSAData End Sub
J'ai jeté un œil aux tutoriels de créations de chat en ligne sur developpez.com, ils utilisent les winSock dans des "Form" (formulaire je présume) mais je n'arrive pas a intégrer ça a mon activeX DLL (il faut dire qu'il est teigneux le bougre...)
Sauriez vous m'aider?
Merci d'avance pour vos réponses.
Remy.
Partager