Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection problem

 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,

I am writing simple Server program as follows:

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

public class Server
{
public static void main(String args[]) throws IOException
{
Server server = new Server();
}

public Server() throws IOException
{
ServerSocket serversocket = new ServerSocket(80);

Socket socket = serversocket.accept();

System.out.println("BYE");

}

}

And my MIDP client has the following code:


import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.rms.*;
import javax.microedition.io.*;
import java.io.*;

public class First extends MIDlet
{
private Display display;
private final static String URL = "http://localhost:80";

private DataOutputStream output;
private StreamConnection stream;

public void destroyApp(boolean flag)
{}

public void pauseApp()
{}

public void startApp()
{
System.out.println("HI");

if (display == null)
{
try
{initMIDlet();}

catch(IOException io)
{ System.out.println("EXCEPTION :" + io); }
}
}

private void initMIDlet() throws IOException
{
display = Display.getDisplay(this);
output = (DataOutputStream) Connector.openDataOutputStream(URL);

System.out.println("CONNECTION CLOSED FROM CELL PHONE");

}

}

-------------------------------------------------------------------------

The problem i am facing is when I launch midp from phone then I get the following output:

HI
CONNECTION CLOSED FROM CELL PHONE

But my server program keeps on waiting for the connection. It never says BYE but whereas when I create simple client by using sockets then my server program says BYE . Where is the problem ?. Sicnce profile is CLDC1.0 but my Sevrer program must accept the connection.

gurpreet
 
eduardo rm
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using something like this in your MIDlet:

import javax.microedition.io.SocketConnection;
public SocketConnection sc;
sc = (SocketConnection) Connector.open("socket://127.0.0.1:1234");

Take a look in file security.policy of your runtime.
You should include some parameters you need.
 
Gurpreet Saini
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic