• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

J2se server and J2me client

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi !
I am making an application for wireless communication between a pc and mobile.
Kindlylet me know that which api I have to use at J2se side.

Thanks for help.
Regards
Rana Jawad
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out javax.microedition.io.SocketConnection on the client side and java.net.ServerSocket on the server side.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm also doing a project in j2me j2se wireless connection using N96.

I'm trying your suggestion using socket server connection and it works well in simulator (server prints:"Hello from socket").However it didn't when i try it from my N96.Here is the code I'm using:

------------------------------------------------------------------------------
J2ME client:

try{
SocketConnection sc = (SocketConnection)
Connector.open("socket://10.217.141.150:4444");
StringBuffer sb = new StringBuffer();
OutputStream os = null;

os = sc.openOutputStream();
byte[] data = "Hello from a socket!".getBytes();
os.write(data);

os.close();
sc.close();

// }
} catch (IOException x){
x.printStackTrace();
}


J2SE server:
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(4444);
} catch (IOException e) {
System.err.println("Could not listen on port: 4444.");
System.exit(1);
}

Socket clientSocket = null;
try {
clientSocket = serverSocket.accept();
} catch (IOException e) {
System.err.println("Accept failed.");
System.exit(1);
}

// BufferedWriter out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
PrintWriter out = new PrintWriter(
clientSocket.getOutputStream(), true);

BufferedReader in = new BufferedReader(
new InputStreamReader(
clientSocket.getInputStream()));
StringBuffer sb = new StringBuffer();
int ch = 0;

while ((ch = in.read()) != -1){
sb.append((char)ch);

//
}
in.close();

clientSocket.close();
serverSocket.close();

---------------------------------------------------------------------
PLease help if anybody know the solution.Thanks!

Best Regards,
 
feri guretno
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Besides, I also try using http connection instead of server socket connection as in http://developers.sun.com/mobility/midp/articles/tutorial2/

Again, it works well in simulator but when I deploy it to N96 i'm getting java.io.IOexception:-33 ( I've changed the url from http://localhost:8080/midp/hits into http://10.217.141.150:8080/midp/hits)

However it can display the html scripts response when i change the url into www.google.com or www.yahoo.com.

Is it the problem with the url?

Thanks for your help in advance!

Best Regards,
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have faced the similar kind of problems with nokia devices , try to encode the url and see if it works

your url

http://10.217.141.150:8080/midp/hits

encoded url

http://10.217.141.150%3A8080/midp/hits
 
feri guretno
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

thanks for the reply.

I've tried using the encoded url in the http connection and it still produce the same exception.

I also tried using http://10.217.141.150%3A4444 for the socket connection and it get "system error, application will be closed" . previously, using http://10.217.141.150:4444 , i get java.io.IOException:SymbianOS error=-191:Internet:Unable to connect to server.

any other solution?

:roll:

 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have worked with http and https connection with encoded url and it has worked fine. Not very sure about socket connection.
 
Saloon Keeper
Posts: 28663
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should not have to encode the ":" that separates the server address from the port in a URL. In fact, I'm surprised that it works.

The problem is that when using a mobile device to access a 10.x.x.x IP address, the device is attempting to locate a non-public IP address via the public internet gateway provided by the phone service provider.

The private-use IP addresses are reserved for use outside the public Internet, and unlike the public IP addresses, they are not unique. I have some 10.x.x.x addresses in use on my own network used for various virtual machines to communicate with each other. These addresses cannot be see by anyone outside my LAN.
 
feri guretno
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, thanks for the reply

FYI, I connect to the wireless in offline mode, with no SIM card inserted. So without the phone service provider, how do the phone know it'spublic internet gateway?is it hardcoded in the phone itself?

And i connect using a wireless router inside my own network, so i thought it should be able to access a non-public ip address( 10.x.x.x) just like if we do it through PC with LAN connection.

So does it mean that the j2se server have to be made to public ip address ( can be accessed outside LAN network) to enable the j2me client to connect to it through http or socket connetion?

Best Regards,
 
Tim Holloway
Saloon Keeper
Posts: 28663
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't have a SIM card installed, your phone is offline. so it can't access any part of the Internet through the phone service provider.

But it sounds like you have a smartphone with WiFi, USB, and/or Bluetooth networking.

Each of those networks has its own network adapter, and each network adapter has its own IP address. Usually, that address is assigned by a DHCP server accessed from whatever gateway device the adapter is communicating with.

This is no different than a desktop unit with multiple NICs in it, or a laptop with both ethernet and WiFi in operation. The core network software includes routing tables that are used to select an interface to communicate.

Yes, if you have a WiFi, you'll be able to access whatever parts of the network any device connecting through that WiFi access point can access.

Of course, if you don't have the WiFi turned on and connected to the access point, the phone won't route, any more that a PC can route if the cable isn't connected.

That's just the basics. If you have paranoid network engineers, they might be firewalling the particular nodes and ports you want to talk to. In that case, you have to convince them to open up the network for you.
 
feri guretno
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

That's just the basics. If you have paranoid network engineers, they might be firewalling the particular nodes and ports you want to talk to. In that case, you have to convince them to open up the network for you.



I set up a tomcat server in my pc as in http://developers.sun.com/mobility/midp/articles/tutorial2/ .It can be accesses from other computer through LAN connection by accessing http://10.217.141.150:8080. However it cannot be accesses from mobile phone. So by saying "to open up the network for you", do you mean to open the port so that it can be accessed from outside LAN network?

because there is a server with address 192.x.x.x which the port have been opened to be accessed from outside LAN network, and I can connect to that server using the mobile phone.

Thanks in advance!!

Best Regards,
 
Tim Holloway
Saloon Keeper
Posts: 28663
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Port 8080 may be blocked, either on the server machine or in one of the routers between your mobile and the server machine.
reply
    Bookmark Topic Watch Topic
  • New Topic