File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java Micro Edition and the fly likes client server programming in j2me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "client server programming in j2me" Watch "client server programming in j2me" New topic

client server programming in j2me

Santhana Lakshmi.S
Ranch Hand

Joined: Aug 16, 2005
Posts: 82
I am having one client program running in mobile and i created a server in the desktop.and i tried to send hi message from the client running in the mobile to the server.
For client i created a socket like this(sample coding given along with the sun java WTK toolkit)
SocketConnection sc = (SocketConnection)"socket://"); is the ip address of the machine in which my server is running.
i wrote my server codings in java and the following is the code

class Server {
public static void main(String args[]) {
String data = "Data sent by server to client";
String line;
try {
ServerSocket srvs = new ServerSocket(8080);
Socket skt = srvs.accept();
System.out.print("Server has connected!\n");
InputStream sin = skt.getInputStream();
OutputStream sout = skt.getOutputStream();

DataInputStream in = new DataInputStream(sin);
DataOutputStream out = new DataOutputStream(sout);
byte[] buffer = new byte[1024];
int len;
while((len = > 0) {
String req = new String(buffer,0,len);
catch(Exception e) {

In emulator this program is working fine and i am able to send message from the client to the server.
I installed my client program in the Nokia6630 mobile and tried to connect to the server,at that time client-server connection itself not establishing.

Can anyone tell me how to establish a simple client server connection?
Thanks a lot
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Is your server a publically available server with that IP address? Also in the J2ME code you say it used port 5000, but in the java code it says port 8080.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Santhana Lakshmi.S
Ranch Hand

Joined: Aug 16, 2005
Posts: 82
yes it is public server my program i used the same port number only.
i checked once again also.while posting the question i mistyped the port number.
Girish Nagaraj
Ranch Hand

Joined: Apr 19, 2006
Posts: 153
Hi lakshmi,

How did you make your server publicly available?
Santhana Lakshmi.S
Ranch Hand

Joined: Aug 16, 2005
Posts: 82
i hosted my server program and running that program in a remote system.
I agree. Here's the link:
subject: client server programming in j2me
It's not a secret anymore!