Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User NickKovach's Avatar
    Join Date
    Dec 2006
    Posts
    10
    hello

    strange problem: i wrote for PC a simple TCP server which accepts TCP connections on port 6168.

    From mobile (5500sport) i can connect this server from browser if i enter URL 80.68.5.132:6168

    Of cause my simple server on PC is not a web server but it detects fact of connection from mobile for sure.

    But when i write my java MIdlet for mobile which makes same URL open then i do not see connection.

    public boolean Open(String server_name)
    {
    try {
    sc = (SocketConnection) Connector.open("socket://80.68.1.132:6168");
    sc.setSocketOption(SocketConnection.DELAY, 0);

    is = sc.openInputStream();
    //os = sc.openOutputStream();

    return true;
    }
    catch (ConnectionNotFoundException cnfe)
    {
    return false;
    }
    catch(IOException ioe)
    {
    return false;
    }
    }

    I do not know why my JAVA application cannot connect.
    What i do incorrect?

    nick

  2. #2
    Super Contributor peterblazejewicz's Avatar
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,699
    hi,

    any exception thrown in midlet or it just does not see to go through data carrier gateways?

    regards,
    Peter

  3. #3
    Registered User NickKovach's Avatar
    Join Date
    Dec 2006
    Posts
    10
    Quote Originally Posted by peterblazejewicz
    hi,

    any exception thrown in midlet or it just does not see to go through data carrier gateways?

    regards,
    Peter
    ---------------------------
    hm..
    i do not know..
    probably exception raised but catched - You see from code that i trying to catch 2 types of exceptions - ConnectionNotFoundException and IOException.

    Which exception happens i do not know yet - i should check.

    Anyway it looks so: when starting connection my App hangs for long time - maybe 1-2 minutes and only after that it says cannot connect when Open() function returns false.

    Besides that same midlet works fine from emulator.

    Other interesting point: i got example of nokia from
    MIDP_2_0_Introduction_to_Using_Sockets_and_Datagrams_v1_0_1.zip

    Called TCPMidlet - it behaves exactly as my own application - when connecting long nothing and then says error.

    I feel that probably matter is not a midlet java source itself but maybe mobile phone configuration? But how to configure phone? Phone browser works fine with internet so mobile looks configured OK.

    Maybe i should sign midlet or similar? I am new in mobile programming and maybe i do not know some tips?

    Please help me

  4. #4
    Regular Contributor Summerman's Avatar
    Join Date
    Feb 2006
    Posts
    150
    Hi NickKovach and Peter!

    After fighting several weeks with TCP/UDP connections, in a real test I noticed that my MIDlet didn't connect to a ServerSocket that was running in a Servlet in a remote PC. The URL was perfect: "socket://hostort" and the "host" and "port" values were correctly too.

    My problem was that the implementation noticed that the phone didn't have a real connection established at the same time that the socket was open! Finally, the code threw an Exception because the socket connection wasn't really open. If the Exception is thrown, no more attempts to open the socket are made!
    I used a WLAN connection and it took one minute or two until getting the connection!

    To sum up: You need to use a "loop" where you try to connect to your particular server socket (with the correct URL) and repeat this operation until you get it! If an Exception occurs, close the connections. Don't forget to close the connections previously to reopen them!
    One of these attempts will work your socket connection!

    I hope this explanation would be useful for you!

    Summerman. --

  5. #5
    Regular Contributor chinlin's Avatar
    Join Date
    Dec 2006
    Posts
    72
    Quote Originally Posted by Summerman
    Hi NickKovach and Peter!

    After fighting several weeks with TCP/UDP connections, in a real test I noticed that my MIDlet didn't connect to a ServerSocket that was running in a Servlet in a remote PC. The URL was perfect: "socket://hostort" and the "host" and "port" values were correctly too.

    My problem was that the implementation noticed that the phone didn't have a real connection established at the same time that the socket was open! Finally, the code threw an Exception because the socket connection wasn't really open. If the Exception is thrown, no more attempts to open the socket are made!
    I used a WLAN connection and it took one minute or two until getting the connection!

    To sum up: You need to use a "loop" where you try to connect to your particular server socket (with the correct URL) and repeat this operation until you get it! If an Exception occurs, close the connections. Don't forget to close the connections previously to reopen them!
    One of these attempts will work your socket connection!

    I hope this explanation would be useful for you!

    Summerman. --
    Hi Summerman,
    Do you mean that you have madethe socket class successfuly worked?
    or not worked at all?

    Thanks,
    Chinlin

  6. #6
    Regular Contributor Summerman's Avatar
    Join Date
    Feb 2006
    Posts
    150
    Hi Chinlin,
    I tested some different J2ME communication classes work! Excuse me, for not expecify what classes are.

    Concretely, they are:

    1) The "UDPDatagramConnection" class.

    2) The "SocketConnection" class.

    3) The "ServerSocketConnection" class.

    In your case, you are interesting in the "SocketConnection" class. Here, I include a snippet of my code:

    Code:
    	
            private void openCommUntilIsConnectedToServer(){
    		
    		do{
    			
    			reOpenComm(1000);
    			
    		}while(!connectedToNetwork);		
    	}
    
    
    	private void reOpenComm(int pause){		
    		try {
    			closeComm();//closeComm() manages its Exceptions!
    			
    			Thread.sleep(pause);
    			
    			openComm();//openComm() manages its Exceptions!
    			
    		}catch (InterruptedException ie) {
    			//Ignored
    		} 
    	}
    	
            private void openComm() {
    
    		try{
    			
    			// Create an outbound socket for the corresponding url. 
    			sc = (SocketConnection)Connector.open(url);
    			
    			//Set the socket options
    			setSocketOptions(DELAY_VALUE, LINGER_VALUE, KEEPALIVE_VALUE, RCVBUF_SIZE, SNDBUF_SIZE);
    			
    			//Open the DataOutputStream and the DataInputStream objects.
    			dos=sc.openDataOutputStream();
    			dis=sc.openDataInputStream();
    			connectedToNetwork=true;
    
    		}catch (Exception e){
                        //Ignored
    		}
    I expect this snippet code will help you!

    Best regards.

    Summerman.

  7. #7
    Regular Contributor chinlin's Avatar
    Join Date
    Dec 2006
    Posts
    72
    Hi,
    Many thanks to you

Similar Threads

  1. Nokia s60 SDK v2.0 - emulator network connection problem
    By eikka4 in forum Symbian Tools & SDKs
    Replies: 14
    Last Post: 2007-03-08, 06:53
  2. Problem with connection timeout
    By maniac_2k in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2006-09-21, 20:12
  3. Replies: 0
    Last Post: 2003-12-08, 10:47
  4. HTTP Connection in S60 Simulator, Problem?
    By photonman in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2003-08-29, 22:10
  5. Nokia 6310i & Mac 17" powerbook bluetooth connection problem
    By scarylittlevoices in forum Bluetooth Technology
    Replies: 1
    Last Post: 2003-08-21, 14:48

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved