Skip to main content

socket programming in j2me

Well, I found the code for client side everytime but i am not able to find a code working on the server end. So, I ma posting a working code:

import java.io.*;
import java.net.*;



public class mpp_usr {

public static void main ( String args[])throws IOException
{
Socket sock = null;
String str =null;
InputStream in;
byte b[] = new byte[1024];
try
{

ServerSocket ss = new ServerSocket(9000);

sock = ss.accept();
in = sock.getInputStream();

DataInputStream din = new DataInputStream(in);

int len;
while((len = din.read(b)) > 0) {
String req = new String(b,0,len);
System.out.print(req);
}

}
catch(IOException ioe)
{
System.out.println("error");
}
}
}

Comments