Win a copy of Microservices in Action this week in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Connection problem  RSS feed

 
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
 
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,
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!