Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. how to make a listener to receive from HttpConnection

how to make a listener to receive from HttpConnection

Scheduled Pinned Locked Moved Java
javasysadminhelptutorialquestion
11 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    williamroma
    wrote on last edited by
    #1

    7 close hi how are you today <b>(SORRY FOR MY BAD ENGLISH)</b> i want to sent data from Server to J2ME (using Java) but i don't know when the server will send the data to my midlet so how can i built a listener in midlet that listen to the resposne from server by (sure that response will receive using HTPPCOnnection) plz help me , i need the solution and tyvm.

    J 1 Reply Last reply
    0
    • W williamroma

      7 close hi how are you today <b>(SORRY FOR MY BAD ENGLISH)</b> i want to sent data from Server to J2ME (using Java) but i don't know when the server will send the data to my midlet so how can i built a listener in midlet that listen to the resposne from server by (sure that response will receive using HTPPCOnnection) plz help me , i need the solution and tyvm.

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      IP traffic is based on two ends of the communication chain. TCP is built on IP. TCP has a 'client' and a 'server'. The client connects to the server (this has nothing to do with what the applications that contain the functionality are named.) HTTP is built on TCP. So in answer to your question. 1. You must have a 'server' that handled HTTP. 2. You then create a 'client' which sends HTTP requests to the 'server'. You can't do anything unless you have both parts. The server cannot be transitory. It must basically be up all the time. In other words it cannot come into existence only once a client sends a request.

      W 2 Replies Last reply
      0
      • J jschell

        IP traffic is based on two ends of the communication chain. TCP is built on IP. TCP has a 'client' and a 'server'. The client connects to the server (this has nothing to do with what the applications that contain the functionality are named.) HTTP is built on TCP. So in answer to your question. 1. You must have a 'server' that handled HTTP. 2. You then create a 'client' which sends HTTP requests to the 'server'. You can't do anything unless you have both parts. The server cannot be transitory. It must basically be up all the time. In other words it cannot come into existence only once a client sends a request.

        W Offline
        W Offline
        williamroma
        wrote on last edited by
        #3

        ty but.. how can i take the ip of an mobile and what is the ip of the local host and if you have any code example to deal with it tyvm

        J 1 Reply Last reply
        0
        • J jschell

          IP traffic is based on two ends of the communication chain. TCP is built on IP. TCP has a 'client' and a 'server'. The client connects to the server (this has nothing to do with what the applications that contain the functionality are named.) HTTP is built on TCP. So in answer to your question. 1. You must have a 'server' that handled HTTP. 2. You then create a 'client' which sends HTTP requests to the 'server'. You can't do anything unless you have both parts. The server cannot be transitory. It must basically be up all the time. In other words it cannot come into existence only once a client sends a request.

          W Offline
          W Offline
          williamroma
          wrote on last edited by
          #4

          but i dont't want to use socket tyvm

          J 1 Reply Last reply
          0
          • W williamroma

            but i dont't want to use socket tyvm

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #5

            williamroma wrote:

            but i dont't want to use socket

            Huh? HTTP is protocol based on TCP, thus sockets. Thus your statement in the context of your question is nonsensical.

            1 Reply Last reply
            0
            • W williamroma

              ty but.. how can i take the ip of an mobile and what is the ip of the local host and if you have any code example to deal with it tyvm

              J Offline
              J Offline
              jschell
              wrote on last edited by
              #6

              williamroma wrote:

              how can i take the ip of an mobile

              Why? If you want the mobile to act as a client (and you can use sockets) then your question is meaningless. If you want the mobile to act as a server then you must have an IP that is visible to the client. This however in general isn't what mobiles do but if it has the IP and sockets (which it would if it has an IP) then it is possible. Whether it is visible is a different issue. Other than that you are asking a question about a specific mobile device because they are all different. It is pointless to ask how to do something on a mobile if it does not in fact have the minimum capability to support the solution. And whether it has Ip is not something that you determine with Java. Instead you look at the specification of the mobile itself.

              W 1 Reply Last reply
              0
              • J jschell

                williamroma wrote:

                how can i take the ip of an mobile

                Why? If you want the mobile to act as a client (and you can use sockets) then your question is meaningless. If you want the mobile to act as a server then you must have an IP that is visible to the client. This however in general isn't what mobiles do but if it has the IP and sockets (which it would if it has an IP) then it is possible. Whether it is visible is a different issue. Other than that you are asking a question about a specific mobile device because they are all different. It is pointless to ask how to do something on a mobile if it does not in fact have the minimum capability to support the solution. And whether it has Ip is not something that you determine with Java. Instead you look at the specification of the mobile itself.

                W Offline
                W Offline
                williamroma
                wrote on last edited by
                #7

                ty 4 ur help mabye i understand u but i wana tell u all the problem i want to make a chat program on Moblie the program using emails on Hotmail the chat include sending and receving IM i can send the IM to my server then the server send it to the person (that i make chat with) but with the person sends me a IM i can catch it in the server but how can i send it to the mobile here is the problem cos i use HttpConnection look: the function protected void doGet(HttpServletRequest request, HttpServletResponse response) be in the server i can send the IM from J2ME client to server and catch it in the request but when someone send the IM to the server how can i send it back to my J2ME client. i know what i hv to use response but this object don't wait for the user to send data .. other words i dont know when the send the data to the server and so i do not know when i hv to send it to the client plz help me , i have to make it , plz plz plz help me tyvm

                J 1 Reply Last reply
                0
                • W williamroma

                  ty 4 ur help mabye i understand u but i wana tell u all the problem i want to make a chat program on Moblie the program using emails on Hotmail the chat include sending and receving IM i can send the IM to my server then the server send it to the person (that i make chat with) but with the person sends me a IM i can catch it in the server but how can i send it to the mobile here is the problem cos i use HttpConnection look: the function protected void doGet(HttpServletRequest request, HttpServletResponse response) be in the server i can send the IM from J2ME client to server and catch it in the request but when someone send the IM to the server how can i send it back to my J2ME client. i know what i hv to use response but this object don't wait for the user to send data .. other words i dont know when the send the data to the server and so i do not know when i hv to send it to the client plz help me , i have to make it , plz plz plz help me tyvm

                  J Offline
                  J Offline
                  jschell
                  wrote on last edited by
                  #8

                  williamroma wrote:

                  i have to make it

                  Why?

                  williamroma wrote:

                  but i wana tell u all the problem

                  And I already told you the most significant part of the problem. You must determine what the mobile can do. That isn't a java question. It isn't a question you can answer about a "mobile". You need to ask it about a specific (vendor) mobile.

                  williamroma wrote:

                  the program using emails on Hotmail

                  That at least makes it likely that it can act as a client.

                  williamroma wrote:

                  plz help me

                  I suggest you write the code, client and server on a desktop first.

                  W 1 Reply Last reply
                  0
                  • J jschell

                    williamroma wrote:

                    i have to make it

                    Why?

                    williamroma wrote:

                    but i wana tell u all the problem

                    And I already told you the most significant part of the problem. You must determine what the mobile can do. That isn't a java question. It isn't a question you can answer about a "mobile". You need to ask it about a specific (vendor) mobile.

                    williamroma wrote:

                    the program using emails on Hotmail

                    That at least makes it likely that it can act as a client.

                    williamroma wrote:

                    plz help me

                    I suggest you write the code, client and server on a desktop first.

                    W Offline
                    W Offline
                    williamroma
                    wrote on last edited by
                    #9

                    the code in Client j2me i beggin received when i pressed receivedChat /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package myPage; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; import javax.microedition.lcdui.Choice; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.List; import javax.microedition.lcdui.StringItem; import javax.microedition.lcdui.TextField; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; /** * * @author William */ public class Main extends MIDlet implements CommandListener { //HTTPCONNECTION // HttpConnection hc = null; OutputStream out = null; InputStream in = null; String URL = "http://localhost:8080/DeleteWebApplication/RomaServlet"; //GUI IN J2ME Display display = null; Form mainScreem = null; TextField emailTextfield = null; TextField passwordTextfield = null; Form contactScreem = null; Command loginCommand = null; Command getContactsCommand = null; //ACCONT IN MSN String sessionId; //GUI FOR ERROR CONNECTION Form errorScreem = null; StringItem errorMessege = null; Command back = null; //MY ACCOUNT IN MSN int numberOfContacts; //GUI FOR CONTACTS FRIENDLYNAMES Form ContactsList = null; StringItem[] contactsListGui = null; //GUI FOR CHAT WITH ONE CONTACTS Form chatScreem = null; Command backToContactsList = null; Command sendIMToContact = null; public Main() { display = Display.getDisplay(this); mainScreem = new Form("Welcome..."); emailTextfield = new TextField("Email", "", 100, TextField.ANY); passwordTextfield = new TextField("Password", "", 100, TextField.PASSWORD); contactScreem = new Form("Your Contacts are:"); loginCommand = new Command("login", Command.BACK, 1); getContactsCommand = new Command("get commands", Command.OK, 2); mainScreem.append(emailTextfield); mainScreem.append(passwordTextfield); mainScreem.addCommand(loginCommand); mainScreem.addC

                    W 1 Reply Last reply
                    0
                    • W williamroma

                      the code in Client j2me i beggin received when i pressed receivedChat /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package myPage; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.microedition.io.Connector; import javax.microedition.io.HttpConnection; import javax.microedition.lcdui.Choice; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.List; import javax.microedition.lcdui.StringItem; import javax.microedition.lcdui.TextField; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; /** * * @author William */ public class Main extends MIDlet implements CommandListener { //HTTPCONNECTION // HttpConnection hc = null; OutputStream out = null; InputStream in = null; String URL = "http://localhost:8080/DeleteWebApplication/RomaServlet"; //GUI IN J2ME Display display = null; Form mainScreem = null; TextField emailTextfield = null; TextField passwordTextfield = null; Form contactScreem = null; Command loginCommand = null; Command getContactsCommand = null; //ACCONT IN MSN String sessionId; //GUI FOR ERROR CONNECTION Form errorScreem = null; StringItem errorMessege = null; Command back = null; //MY ACCOUNT IN MSN int numberOfContacts; //GUI FOR CONTACTS FRIENDLYNAMES Form ContactsList = null; StringItem[] contactsListGui = null; //GUI FOR CHAT WITH ONE CONTACTS Form chatScreem = null; Command backToContactsList = null; Command sendIMToContact = null; public Main() { display = Display.getDisplay(this); mainScreem = new Form("Welcome..."); emailTextfield = new TextField("Email", "", 100, TextField.ANY); passwordTextfield = new TextField("Password", "", 100, TextField.PASSWORD); contactScreem = new Form("Your Contacts are:"); loginCommand = new Command("login", Command.BACK, 1); getContactsCommand = new Command("get commands", Command.OK, 2); mainScreem.append(emailTextfield); mainScreem.append(passwordTextfield); mainScreem.addCommand(loginCommand); mainScreem.addC

                      W Offline
                      W Offline
                      williamroma
                      wrote on last edited by
                      #10

                      this is the serverlet in the server public class RomaServlet extends HttpServlet { public void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override public String getServletInfo() { return "Short description"; } MsnMessenger messenger = null; BasicMessenger m = null; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String type = request.getHeader("type"); System.out.println("my Type is :" + type); if (type.equals("1")) { HttpSession session = request.getSession(false); int hits = 0; BufferedReader br = request.getReader(); int len = br.read();//the length of Email ... String email = ""; for (int i = 0; i < len; i++) { email += (char) br.read(); } String password = ""; int ch; while ((ch = br.read()) != -1) { password += (char) ch; } if (session == null) { session = request.getSession(true); session.setAttribute("Count", hits); m = new BasicMessenger(); session.setAttribute("messenger", m); Listener l = new Listener(session); session.setAttribute("rere", ""); try { m.start(messenger, email, password); } catch (InstantiationException ex) { Logger.getLogger(RomaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(RomaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(RomaServlet.class.getName()).log(Level.SEVERE, null, ex); } } session.setAttribute("Count", 1 + (Integer) session.getAttribute("Count")); response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.println("Complete Login"); } else //if(type.equals("2"))

                      W 1 Reply Last reply
                      0
                      • W williamroma

                        this is the serverlet in the server public class RomaServlet extends HttpServlet { public void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } @Override public String getServletInfo() { return "Short description"; } MsnMessenger messenger = null; BasicMessenger m = null; @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String type = request.getHeader("type"); System.out.println("my Type is :" + type); if (type.equals("1")) { HttpSession session = request.getSession(false); int hits = 0; BufferedReader br = request.getReader(); int len = br.read();//the length of Email ... String email = ""; for (int i = 0; i < len; i++) { email += (char) br.read(); } String password = ""; int ch; while ((ch = br.read()) != -1) { password += (char) ch; } if (session == null) { session = request.getSession(true); session.setAttribute("Count", hits); m = new BasicMessenger(); session.setAttribute("messenger", m); Listener l = new Listener(session); session.setAttribute("rere", ""); try { m.start(messenger, email, password); } catch (InstantiationException ex) { Logger.getLogger(RomaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(RomaServlet.class.getName()).log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { Logger.getLogger(RomaServlet.class.getName()).log(Level.SEVERE, null, ex); } } session.setAttribute("Count", 1 + (Integer) session.getAttribute("Count")); response.setContentType("text/plain"); PrintWriter out = response.getWriter(); out.println("Complete Login"); } else //if(type.equals("2"))

                        W Offline
                        W Offline
                        williamroma
                        wrote on last edited by
                        #11

                        this is the listener in the server when i receive the IM it is automaticllaly called the function instantMessageReceived (SORRY FOR MY BAD ENGLISH) (THANK YOU VERY MUCH) /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package example; import java.io.IOException; import java.io.PrintWriter; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.http.HttpServletResponse; import net.sf.jml.MsnContact; import net.sf.jml.MsnMessenger; import net.sf.jml.MsnSwitchboard; import net.sf.jml.event.MsnAdapter; import net.sf.jml.message.MsnDatacastMessage; import net.sf.jml.message.MsnInstantMessage; /** * * @author William */ public class TottiLisner extends MsnAdapter{ public boolean rrr=false; public MsnInstantMessage mmm; public PrintWriter out; public void exceptionCaught(MsnMessenger messenger, Throwable throwable) { for(int i=0;i<10;i++) System.out.println("TOTTI TOTTI TOTTI TOTTI TOTTI TOTTI"); } public void instantMessageReceived(MsnSwitchboard switchboard, MsnInstantMessage message, MsnContact friend) { rrr=true; this.mmm=message; } public void datacastMessageReceived(MsnSwitchboard switchboard, MsnDatacastMessage message, MsnContact friend) { for(int i=0;i<10;i++) System.out.println("BUFFON BUFFON BUFFON BUFFON BUFFON"); } }

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups