bonjour,
j'ai crée un classe socket appelant des fonctions native pour acceder un C
compliation
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 import java.awt.*; import java.awt.event.*; import java.util.*; import java.applet.*; import java.applet.Applet; import javax.swing.*; import java.awt.Toolkit; public class Socket2 implements Runnable { Thread tr = null ; JavaVersC pSocket = null ; public class JavaVersC { public native long OpenTxSocket( int iProtocol, String IpAddress, int iPortIp, int iTTL, String szIpAddressToBind, int iPortToBind); public native boolean CloseTXSocket(long SockTX); public native boolean SendTXSocket( long SockTX, String Buffer); public native long OpenRxSocket ( int iProtocol, String szIpAddress, int iPortToBind, String szIpAddressToBind, int iPortIp); public native boolean CloseRXSocket(long SockRX); public native String ReceiveRXSocket(long SockRX); public native String SyncReceiveRXSocket( long SockRX, int iTimeOut); public native String SendAndSyncReceive( long SockTX, String szSend, long SockRX, int iTimeOut); public native boolean SendAndSyncReceiveWithCallBack( long SockTX, String szSend, long SockRX, int iTimeOut, String Name, String Type); public void CallbackSocket(String Buffer) { System.out.println("CallbackSocket IN\r\n"); System.out.println("CallbackSocket : " + Buffer); System.out.println("\r\n"); } public JavaVersC() { System.loadLibrary("JavaVersC"); //System.load("w:/java/JavaVersC.dll"); } } public Socket2() { System.out.println(" Socket Constructeur\r\n "); if (pSocket == null) { pSocket = new JavaVersC(); if (pSocket != null) { System.out.println(" Socket OK\r\n "); } else { System.out.println(" Socket Failed\r\n "); } } if (tr == null) { tr = new Thread(this); tr.start(); } } public static void main(String args[]) { System.out.println(" Socket main\r\n "); new Socket2(); } public void run() { System.out.println(" Socket run\r\n "); while (true) { try { System.out.println(" Socket run\r\n "); Thread.sleep(1000); } catch(InterruptedException e) { } } } public void init() { System.out.println(" Socket init\r\n "); } }
Lancement
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 javac Socket2.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 java Socket2
Pour cette classe, lancer en ligne en console, le chargement de la dll se fait bien
Mais je voudrais l'utiliser dans un applet afin d'interagir avec une page web
j'ai voulus faire :
compliation
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 import java.awt.*; import java.awt.event.*; import java.util.*; import java.applet.*; import java.applet.Applet; import javax.swing.*; import java.awt.Toolkit; public class Socket extends Applet implements Runnable { Thread tr = null ; JavaVersC pSocket = null ; public class JavaVersC { public native long OpenTxSocket( int iProtocol, String IpAddress, int iPortIp, int iTTL, String szIpAddressToBind, int iPortToBind); public native boolean CloseTXSocket(long SockTX); public native boolean SendTXSocket( long SockTX, String Buffer); public native long OpenRxSocket ( int iProtocol, String szIpAddress, int iPortToBind, String szIpAddressToBind, int iPortIp); public native boolean CloseRXSocket(long SockRX); public native String ReceiveRXSocket(long SockRX); public native String SyncReceiveRXSocket( long SockRX, int iTimeOut); public native String SendAndSyncReceive( long SockTX, String szSend, long SockRX, int iTimeOut); public native boolean SendAndSyncReceiveWithCallBack( long SockTX, String szSend, long SockRX, int iTimeOut, String Name, String Type); public void CallbackSocket(String Buffer) { System.out.println("CallbackSocket IN\r\n"); System.out.println("CallbackSocket : " + Buffer); System.out.println("\r\n"); } public JavaVersC() { System.loadLibrary("JavaVersC"); } } public Socket() { System.out.println(" Socket Constructeur\r\n "); } public void main(String args[]) { System.out.println(" Socket main\r\n "); new Socket(); } public void run() { System.out.println(" Socket run\r\n "); while (true) { try { repaint(); System.out.println(" Socket run\r\n "); Thread.sleep(1000); } catch(InterruptedException e) { } } } public void init() { System.out.println(" Socket init\r\n "); Dimension dim = getSize(); setBackground(Color.white); if (pSocket == null) { pSocket = new JavaVersC(); if (pSocket != null) { System.out.println(" Socket OK\r\n "); } else { System.out.println(" Socket Failed\r\n "); } } if (tr == null) { tr = new Thread(this); tr.start(); } } }
Lancement
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 javac Socket.java
Mais cette dernier ne fonctionne pas "acces denied"
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 appletviewer.exe Socket.html
que la dll soit dans le rep courant, dans system32 , çà fonctionne pas.
j'ai essaye de faire un jar
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 <html> <head> <title> Page de test HTML </title> </head> <body> <center> Horloge apparaîtra ci-dessous dans un navigateur Java.<br><br><br> <applet code= "Socket.class" name="MyAppletTest" width="125" height="125"> Votre navigateur n'est pas compatible java. </applet> </center> </body> </html>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2jar cvfm Socket.jar Manifest.txt *.class JavaVersC.dll
çà fonctionne toujours 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 <html> <head> <title> Page de test HTML </title> </head> <body> <center> Horloge apparaîtra ci-dessous dans un navigateur Java.<br><br><br> <applet code= "Socket.class" archive = "Socket.jar" name="MyAppletTest" width="125" height="125"> Votre navigateur n'est pas compatible java. </applet> </center> </body> </html>
Quelqu'un pourrait-il m'aider ?
Merci
@+
Partager