Saya mencoba potongan program ini :
StreamConnection SambungPOP;
boolean negative = false;
String requestCommand,respon;
try {
SambungPOP = (StreamConnection)
Connector.open("socket://pop.hotpop.com:110",Connector.READ_WRITE);
SambungPOP.close();
} catch (IOException ioe) {}
lalu keluar Error :
javax.microedition.io.ConnectionNotFoundException: The requested protocol
does not exist socket://pop.hotpop.com:110
Error tersebut keluar saat saya coba dengan menggunakan emulator nokia
3510i SDK. Kalau menggunakan java wireless toolkit, error tadi tidak keluar dan
koneksi berhasil dilakukan.
Berdasarkan yang saya tahu, MIDP 1.0 memang tidak menyediakan koneksi untuk
socket, apa memang benar ?
Saya menemukan di salah satu forum java yang berisi sebagai berikut :
Well, although not supported and maybe not recomended I implemented the socket
protocol in the MIDP. Sometimes you need more than HTTP :-)
It was easy once you knew how to do it. The thing is to trick the
Connector class to
believe that socket is a valid protocol
[Connector.open("socket://<ipaddress>:<port>")].
Using this method you can create what ever protocol you want, like datagram:,
socketserver:, ldap:,....
Actually socket is already in the MIDP; I mean HTTP is using "sockets".
What you have to do is to create a Protocol.class and put it under
com/sun/midp/io/j2me/socket. This is where the Connector classs is looking
for
supported protocols. As you can see only http is available.
The protocol class should extend com.sun.cldc.io.j2me.socket.Protocol. You see
sockets are supported in CLDC, but you are not allowed to use these methods
directly. If you do an exception is thrown - "Should not be called"...
well enough rambling... (as you can see i tried all different stuff before
I got it right)
package com.sun.midp.io.j2me.socket;
import com.sun.cldc.io.ConnectionBase;
import javax.microedition.io.Connection;
import javax.microedition.io.StreamConnection;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
public class Protocol extends com.sun.cldc.io.j2me.socket.Protocol
{
public Connection c;
public Protocol()
{
super();
System.out.println("Protocol.ConnectionBase() called");
}
put this java file together with you MIDlet source and voila socket is at
your service.
At first I put the Protocol.class in the midpapi.zip, since I though the
emulator
used it for the "phones".... It doesn't seem that way.
Cara diatas sudah saya coba, tetapi tetap tidak ada perubahan, apakah ada
cara lain ?
Kalau mau keluar dari mailing list ini, caranya kirim sebuah email ke [EMAIL PROTECTED]
Jangan lupa, website JUG Indonesia adalah http://www.jug.or.id
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/jug-indonesia/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
