Skip to content

Commit 74c7320

Browse files
committed
Added demo app
1 parent 33db5f4 commit 74c7320

40 files changed

+4017
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/build/
2+
/CN1SocketsDemo/nbproject/private/
3+
/CN1SocketsDemo/build/
4+
/CN1SocketsDemo/dist/
144 KB
Binary file not shown.

CN1SocketsDemo/JavaSE.jar

21.4 MB
Binary file not shown.

CN1SocketsDemo/build.xml

+448
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
#Mon Nov 17 10:20:04 PST 2014
3+
codename1.vendor=CodenameOne
4+
codename1.displayName=CN1SocketsDemo
5+
codename1.icon=icon.png
6+
codename1.languageLevel=5
7+
codename1.ios.debug.certificatePassword=
8+
codename1.arg.vserv.transition=3000
9+
codename1.secondaryTitle=CN1SocketsDemo
10+
codename1.version=1.0
11+
package=generated
12+
codename1.mainName=SocketsDemo
13+
codename1.ios.certificatePassword=
14+
codename1.ios.release.provision=
15+
codename1.rim.signtoolDb=
16+
libVersion=80
17+
codename1.ios.release.certificatePassword=
18+
codename1.ios.certificate=
19+
userClass=src/userclasses/StateMachine.java
20+
codename1.j2me.nativeTheme=nbproject/nativej2me.res
21+
codename1.ios.appid=Q5GHSKAL2F.ca.weblite.codename1.sockets.demo
22+
codename1.android.keystorePassword=
23+
codename1.ios.release.certificate=
24+
codename1.rim.signtoolCsk=
25+
codename1.ios.debug.certificate=
26+
mainForm=Main
27+
baseClass=src/generated/StateMachineBase.java
28+
codename1.android.keystore=
29+
guiResource=theme.res
30+
codename1.android.keystoreAlias=
31+
codename1.rim.certificatePassword=
32+
codename1.ios.debug.provision=
33+
codename1.ios.provision=
34+
codename1.packageName=ca.weblite.codename1.sockets.demo

CN1SocketsDemo/icon.png

65.5 KB
Loading

CN1SocketsDemo/lib/CLDC11.jar

1.97 MB
Binary file not shown.

CN1SocketsDemo/lib/CN1Sockets.cn1lib

-136 Bytes
Binary file not shown.

CN1SocketsDemo/lib/CodenameOne.jar

3.18 MB
Binary file not shown.
5.9 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
package ca.weblite.codename1.net.impl;
2+
3+
4+
import java.net.Socket;
5+
public class NativeSocketImpl {
6+
private Socket socket;
7+
private byte[] receiveBuffer, sendBuffer;
8+
private Throwable lastError;
9+
private int bufferId;
10+
private String host;
11+
private int port;
12+
13+
public void setBufferId(int bufferId){
14+
this.bufferId = bufferId;
15+
}
16+
17+
public int getBufferId(){
18+
return bufferId;
19+
}
20+
21+
22+
23+
24+
public int read() {
25+
try {
26+
return socket.getInputStream().read();
27+
} catch ( Throwable t){
28+
lastError = t;
29+
return -2;
30+
}
31+
}
32+
33+
public long skip( long n) {
34+
try {
35+
return socket.getInputStream().skip(n);
36+
} catch (Throwable t){
37+
lastError = t;
38+
return -2;
39+
}
40+
}
41+
42+
public int available() {
43+
try {
44+
return socket.getInputStream().available();
45+
} catch ( Throwable t){
46+
lastError = t;
47+
return -2;
48+
}
49+
}
50+
51+
public boolean markSupported() {
52+
try {
53+
return socket.getInputStream().markSupported();
54+
} catch ( Throwable t ){
55+
lastError = t;
56+
return false;
57+
}
58+
59+
}
60+
61+
62+
63+
public boolean setReceiveBufferSize( int size) {
64+
try {
65+
socket.setReceiveBufferSize(size);
66+
receiveBuffer = new byte[size];
67+
return true;
68+
} catch ( Throwable t ){
69+
lastError = t;
70+
return false;
71+
}
72+
}
73+
74+
public boolean write( int b) {
75+
try {
76+
socket.getOutputStream().write(b);
77+
return true;
78+
} catch ( Throwable t){
79+
lastError = t;
80+
return false;
81+
}
82+
}
83+
84+
public boolean setSendBufferSize( int size) {
85+
try {
86+
socket.setSendBufferSize(size);
87+
sendBuffer = new byte[size];
88+
return true;
89+
} catch ( Throwable t){
90+
lastError = t;
91+
return false;
92+
}
93+
}
94+
95+
public boolean setKeepAlive( boolean on) {
96+
try {
97+
socket.setKeepAlive(on);
98+
return true;
99+
} catch ( Throwable t){
100+
lastError = t;
101+
return false;
102+
}
103+
}
104+
105+
public boolean isInputShutdown() {
106+
return socket.isInputShutdown();
107+
}
108+
109+
public boolean isOutputShutdown() {
110+
return socket.isOutputShutdown();
111+
}
112+
113+
public String getErrorMessage() {
114+
return lastError.getMessage();
115+
}
116+
117+
public boolean closeOutputStream() {
118+
try {
119+
socket.getOutputStream().close();
120+
return true;
121+
} catch ( Throwable t){
122+
lastError = t;
123+
return false;
124+
}
125+
}
126+
127+
public int readBuf(int len) {
128+
byte[] buf = ca.weblite.codename1.net.Socket.getBuffer(bufferId);
129+
try {
130+
return socket.getInputStream().read(buf, 0, len);
131+
132+
} catch ( Throwable t){
133+
lastError = t;
134+
return -2;
135+
}
136+
}
137+
138+
public boolean closeInputStream() {
139+
try {
140+
socket.getInputStream().close();
141+
ca.weblite.codename1.net.Socket.deleteBuffer(bufferId);
142+
return true;
143+
} catch ( Throwable t ){
144+
lastError = t;
145+
return false;
146+
}
147+
}
148+
149+
public int getErrorCode() {
150+
return 0;
151+
}
152+
153+
public boolean createSocket(String host, int port) {
154+
this.host = host;
155+
this.port = port;
156+
return true;
157+
158+
}
159+
160+
public boolean connectSocket(int timeout){
161+
try {
162+
socket = new Socket(host, port);
163+
return true;
164+
165+
} catch ( Throwable t){
166+
lastError = t;
167+
return false;
168+
}
169+
}
170+
171+
public boolean closeSocket() {
172+
try {
173+
socket.close();
174+
ca.weblite.codename1.net.Socket.deleteBuffer(bufferId);
175+
return true;
176+
} catch ( Throwable t){
177+
lastError = t;
178+
return false;
179+
}
180+
}
181+
182+
public boolean writeBuf( byte[] buf) {
183+
try {
184+
socket.getOutputStream().write(buf);
185+
return true;
186+
} catch ( Throwable t){
187+
lastError = t;
188+
return false;
189+
}
190+
}
191+
192+
193+
public boolean resetInputStream() {
194+
try {
195+
socket.getInputStream().reset();
196+
return true;
197+
} catch ( Throwable t){
198+
lastError = t;
199+
return false;
200+
}
201+
}
202+
203+
204+
205+
public boolean isSocketConnected() {
206+
return socket.isConnected();
207+
}
208+
209+
public boolean markInputStream( int readLimit) {
210+
try {
211+
socket.getInputStream().mark(readLimit);
212+
return true;
213+
} catch ( Throwable t){
214+
lastError = t;
215+
return false;
216+
}
217+
}
218+
219+
public boolean isSocketClosed() {
220+
return socket.isClosed();
221+
222+
}
223+
224+
public boolean writeBuffOffsetLength( byte[] buf, int offset, int len) {
225+
try {
226+
socket.getOutputStream().write(buf, offset, len);
227+
return true;
228+
} catch ( Throwable t){
229+
lastError = t;
230+
return false;
231+
}
232+
}
233+
234+
public boolean flushOutputStream() {
235+
try {
236+
socket.getOutputStream().flush();
237+
return true;
238+
} catch ( Throwable t){
239+
lastError = t;
240+
return false;
241+
}
242+
}
243+
244+
public boolean isSupported() {
245+
return true;
246+
}
247+
248+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#import <Foundation/Foundation.h>
2+
#import "xmlvm.h"
3+
#import "ca_weblite_codename1_net_Socket.h"
4+
5+
@interface ca_weblite_codename1_net_impl_NativeSocketImpl : NSObject {
6+
NSInputStream* inputStream;
7+
NSOutputStream* outputStream;
8+
NSString* errorMessage;
9+
int bufferId;
10+
BOOL isFinished;
11+
}
12+
13+
-(int)read;
14+
-(long long)skip:(long long)param;
15+
-(int)available;
16+
-(BOOL)markSupported;
17+
-(BOOL)setReceiveBufferSize:(int)param;
18+
-(BOOL)write:(int)param;
19+
-(void)setBufferId:(int)param;
20+
-(int)getBufferId;
21+
-(BOOL)setSendBufferSize:(int)param;
22+
-(BOOL)setKeepAlive:(BOOL)param;
23+
-(BOOL)isInputShutdown;
24+
-(BOOL)isOutputShutdown;
25+
-(NSString*)getErrorMessage;
26+
-(BOOL)closeOutputStream;
27+
-(int)readBuf:(int)len;
28+
-(BOOL)closeInputStream;
29+
-(int)getErrorCode;
30+
-(BOOL)createSocket:(NSString*)param param1:(int)param1;
31+
-(BOOL)closeSocket;
32+
-(BOOL)writeBuf:(NSData*)param;
33+
-(BOOL)flushOutputStream;
34+
-(BOOL)markInputStream:(int)param;
35+
-(BOOL)connectSocket:(int)param;
36+
-(BOOL)isSocketConnected;
37+
-(BOOL)isSocketClosed;
38+
-(BOOL)writeBuffOffsetLength:(NSData*)param param1:(int)param1 param2:(int)param2;
39+
-(BOOL)resetInputStream;
40+
-(BOOL)isSupported;
41+
@end

0 commit comments

Comments
 (0)