BlackBerryForums.com : Your Number One BlackBerry Community   Wallpaper Megaplex for BlackBerry   

»Sponsored Links



Closed Thread
 
LinkBack Thread Tools
  (#1 (permalink)) Old
fbrimm Offline
Thumbs Must Hurt
 
Posts: 120
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Question Socket connection - 11-11-2005, 08:08 AM

I'm trying to use a socket connection to send/receive xml data, but it doesn't appear that my connection is being made. I'm currently using only the device simulator (7290), the MDS simulator, and have tried the "deviceside" setting both true and false.

I've followed the socketdemo example with some improvements that I've read on the board regarding reading the input. After I open the connection, I send an xml message to the server. From what I can tell the server is never seeing my data or connection.

I'm not receiving any errors from creating the connection or the output of the xml data. The messages displayed on the MDS simulator screen all appear to be normal compared to other programs that are connecting to other servers.

Do I need to add anything to the MDS simulator config file so that my connection is authenticated (ie, username/password)?

Any help or suggestions would be greatly appreciated.

fbrimm
   
Sponsored Links
Please Login or Register to Remove these Advertisements!

  (#2 (permalink)) Old
fbrimm Offline
Thumbs Must Hurt
 
Posts: 120
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Default 11-11-2005, 10:40 AM

It seems like the connection is timing out after only 10 seconds, not the 120 seconds that has been discussed. Its very likely that the server I'm connecting to needs more than 10 seconds to generate its response. Is there any way to keep the connection alive longer? I've tried using the KEEPALIVE option on the SocketConnection, but didn't seem to have any impact.
   
  (#3 (permalink)) Old
ecarmody Offline
Thumbs Must Hurt
 
Posts: 80
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 8100
Carrier: Cingular
Default 11-16-2005, 12:36 AM

Hello,

Why do you believe it is timing out at 10 seconds ... are you getting an exception with string message?

Also, in regards to deviceside and MDS. Are/do you plan to use a BES? If you are not, then set deviceside=true and DO NOT start up the MDS simulator. That is only needed when simulating with a BES environment. If your going to be using a BES, then start up the MDS sim and set deviceside=false.

Actually, I can't really vouche for that last scenario. The only way I got socket connect to realiable work was deviceside=true and no MDS sim.

Eric
   
  (#4 (permalink)) Old
fbrimm Offline
Thumbs Must Hurt
 
Posts: 120
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Default 11-16-2005, 07:43 AM

Hi Eric,

Thanks for the reply.

The MDS log shows entries when my connection is supposedly made and my XML data sent. 10 seconds later it then logs a "DISCONNECT-ORDER" and my thread waiting to receive data ends but nothing was received.

I tried running without the MDS sim and deviceside=true, and now the code just waits to receive a response. It doesn't time out and close the connection like with the MDS sim running, but it still doesn't appear that the connection is really being made.

I'll keep trying...

fbrimm
   
  (#5 (permalink)) Old
ecarmody Offline
Thumbs Must Hurt
 
Posts: 80
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 8100
Carrier: Cingular
Default 11-16-2005, 11:07 AM

In my opinion, the communication contact and connection is made upon return of the (SocketConnection)Connector.open( url ) call. If this returns without error then you've got a connection.

You also indicate that you sent the data, meaning you did a write() of some kind. I assume then that your connector.open() returned successfully and the .write() as well.

At that point, I would question as to the server side is function properly in generating a proper response. Also, I would debug your read thread. Does the loop doing .read() return any bytes ? If you receive some bytes but it stalls at the end and times out (does not receive a EOF), are you checking for a -1 return from the read()?

Eric
   
  (#6 (permalink)) Old
fbrimm Offline
Thumbs Must Hurt
 
Posts: 120
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Default 11-16-2005, 12:52 PM

You are correct. The (SocketConnection)Connector.open(URL) appears to be successful. In fact I've tried using a different server that is not listening for a socket connection, and I receive a connection refused error. So you are correct, the connection to the server seems "real".

I open both InputStreamReader and OutputStreamWriter without any errors.

I send my data to the server with a .write() and that completes without any errors.

I then loop on the .read() while the result is -1. My -1 condition never fails, so I'm not getting anything at all back from the server.

Here is my code segment that is doing the write and waiting to read data. When the DISCONNECT-ORDER shows up in the MDS log, my while loop ends but no data was received.

Thanks.

Code:
        // _in and _out are the streams opened in the run section of this thread
        // data is the string of data to be sent

        private String exchange(String data) throws IOException {
            int length = data.length();
            StringBuffer sb = new StringBuffer();
            int ch;
                
            _out.write(data, 0, length);
                    
            while ((ch = _in.read()) != -1) {
                sb.append((char) ch);
            }
                
            return sb.toString();
                
        }
   
  (#7 (permalink)) Old
ecarmody Offline
Thumbs Must Hurt
 
Posts: 80
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 8100
Carrier: Cingular
Default 11-16-2005, 01:48 PM

So you confirmed the sb length is zero?
Does the exchange() exit by exception or by return sb.toString() ?

Here are some alternate things to try...
static final String EOL = "\r\n";

_out.write(data + EOL);
_out.flush();

Your read loop looks fine to me; it's the same as mine.
   
  (#8 (permalink)) Old
fbrimm Offline
Thumbs Must Hurt
 
Posts: 120
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Default 11-18-2005, 10:27 AM

I've tried setting a breakpoint on the sb.append() line and never hit it.

I have an EOT character that's added to the data before I call exchange, but good catch.

I had not thought about a flush(), but will give that a try and see what happens.

My call to exchange is already inside a "try" statement, so I'm catching any exceptions at that level.

I really appreciate all your time helping me on this. Thanks.
   
  (#9 (permalink)) Old
ecarmody Offline
Thumbs Must Hurt
 
Posts: 80
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 8100
Carrier: Cingular
Default 11-18-2005, 10:42 AM

See how the flush() ends up doing. At this point it sounds like the server is not returning any data. Possible the flush will correct that.

Alternately, to test your code, you could change your port# on your socket connection to 80 (HTTP), and direct your URL to a known web server. This way you will get html response that your read loop should consume and return.

If that does work either, then you have some other communication issues and not necessarily a coding issue.

I'd be interested to hear of the HTTP test worked.

Eric
   
  (#10 (permalink)) Old
fbrimm Offline
Thumbs Must Hurt
 
Posts: 120
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Default 11-18-2005, 02:23 PM

Eric,

Turns out my EOT character was NOT being added, thus the server was timing out and closing the connection after 10 seconds. Go figure...

I've added the flush() statement just to be safe.

Now the problem seems to be my read loop either doesn't see the data, or it never sees the end. If I put a breakpoint at the append() statement, I hit the breakpoint as expected, I clear the breakpoint and let it continue running, everything works fine. If I don't have the breakpoint, it either never exits the read loop, or it never sees the data that I know is there now. For now I've added some logic to look for the EOT charcter and break out of the while loop.

Thanks again for all your help.
   
  (#11 (permalink)) Old
ecarmody Offline
Thumbs Must Hurt
 
Posts: 80
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 8100
Carrier: Cingular
Default 11-20-2005, 01:10 PM

I've had that exact same issue in the past, where the read loop would read data but would stall and timeout at the end and appear as if it never sees a -1 return.

I don't get that situation anymore and I'm not sure one particular thing made it stop or a combination of things. However, I think it has to do with the combination of the APN being specified as well as the deviceside=true. If you haven't specified one yet, go into your Options, TCP, and enter the APN values depending on your service provider. Do a search here in the forums or a google for blackberry apn and you should find a list somewhere with the values. Also, when/if you get exceptions like "malformed DNS" or "bad dns" or "tunnel" errors ... most likely all APN related errors. This would be for your device settings.

When running in the simulator, my APN setting is "rim.net.gprs" and user/pswd are blank.

Again, as I've mentioned before, if your not going to be deploying on a system using a BES, then you don't need to run the MDS sim when doing device sim testing. I don't. I think that by specifying deviceside=true on ALL your connections (even HTTP) voids the need for the MDS simulator. If your running the device simulator and find you cannot get any data connection without having to run the MDS sim, then IMO, that is why your communication is timing out. In one of my apps with does multiple socket connects (FTP port 21) as well as http, all connections are deviceside=true, and I do not need to run the MDS simulator. I think you will see your -1 timeout disappear when you've attained that position.

Cheers,
Eric
   
  (#12 (permalink)) Old
lharts Offline
Knows Where the Search Button Is
 
Posts: 25
Join Date: Jun 2005
Model: 7230
Default 11-24-2005, 04:02 AM

in relation to deviceside=true you have to change ur handheld tcp settings!! it will work ok on simulator but not on realworld device without apn being set properly. there was a very good thread which had a complete list of APN's on this site somewhere.

Also how is ur server reading from the socketconnection? i had a very similiar error and it transpired that my server was trying to read variable amounts of data from the connection thus it mite never just read the end of line byte on its own... simple i know!

so i would suggest putting in a number of println lines to see what exactly is being done, i find this easier and more informative than just doin a straight debug. so print what exactly is being read() as soon as its read etc.

i used
BufferedInputStream _in=new BufferedInputStream(_clientSocket.getInputStream() );
OutputStreamWriter _out=new OutputStreamWriter(_clientSocket.getOutputStream() );

regarding deviceside=true. ecarmody is correct. if you plan on using it dont bother with the MDS.
   
  (#13 (permalink)) Old
abhay Offline
New Member
 
Posts: 1
Join Date: Dec 2005
Model: 7290
Default socket connection - 12-17-2005, 12:52 AM

thx. ppl.

your discussion help me lot.. first time i m working with bb. and don't know how to create socket connection in bb.

and i try bellow.

sc = (SocketConnection) Connector.open("socket://<ip>:<port>;deviceside=true");
sc.setSocketOption(SocketConnection.KEEPALIVE,2);

and i get connection.. now in simulator i can connect with my server. but

what is bes and mds? and how to configure ? with this setting if i deploy my app./game on bb will connection will establish and work fine ?

pls. help me if you know anything or provide me proper link. where i can find out. i send 2-3 days behind this .

thx. again.
best regards
   
  (#14 (permalink)) Old
lharts Offline
Knows Where the Search Button Is
 
Posts: 25
Join Date: Jun 2005
Model: 7230
Default 12-17-2005, 08:19 AM

mds is mobile data service (i think!), adn bes is blackberry enterprise server.

mds is a feature that is installed on a bes. The bes itself is responsible (in cases where its used) for providing a secure connection to a network. it can allow a bb to connect to a corporate lan etc. its main purpose however is to push emails to the bb device as needs be.

its important to note however that not every bb accesses a bes, ie if you purchase a bb thru a service provider the chances are that you wont have access to any bes. however if your company is a big corporation that has a number of poeple using blackberry's then you prob do.

when you use a socket connection pre v4.0 you needed access to a bes, however since v4 its possible to use deviceside=true (as you have above) this means that you dont access a bes to create your socket connection. you do however need to set up ur gprs connection to allow you to access teh internet openly...

there is a very good article on the process for doing it in these forums (sorry i dont ahve time to find a link).

hope the information helps!!
   
  (#15 (permalink)) Old
arcadiop Offline
New Member
 
arcadiop's Avatar
 
Posts: 9
Join Date: Jun 2006
Model: 7100r
Default 07-18-2006, 03:39 PM

Do the Blackberry emulator need MDS activation for run the socket sample?

When I start the MDS (Start Menu or run.bat file) it try to load, but instantly the windows console disappear. What can I do ?

Thanks.
   
  (#16 (permalink)) Old
lharts Offline
Knows Where the Search Button Is
 
Posts: 25
Join Date: Jun 2005
Model: 7230
Default 07-21-2006, 03:47 PM

no the emulator doesnt need the MDS service to be able to run the socket sample. there are a number of ways that it can be set up to run. if you dont need/MDS service you can avoid the issue by setting up the emulator to use a DirectTCP connection as opposed to using the standard socket connection with requires the MDS.

To use the DirectTCP connection in the 'real-world' you simply have to have access to a WAP Gateway which will handle teh socket connectivity transparently for you.

any more questions just ask!

lharts
   
  (#17 (permalink)) Old
eye_s Offline
New Member
 
Posts: 1
Join Date: Jan 2006
Model: 7100i
Carrier: Sprint/Nextel
Default 07-30-2006, 01:55 PM

can you explain how to setup the direct tcp connection in the emulator? i am testing some web applications and just need pure browser functionality without MDS.
   
  (#18 (permalink)) Old
lharts Offline
Knows Where the Search Button Is
 
Posts: 25
Join Date: Jun 2005
Model: 7230
Default 07-31-2006, 03:58 AM

the way i have it set up is as follows...

I have a checkbox that decides whether or not directTCP is used or not. the command is then

URL = "socket://" + _serverip + ":"+_PORT + (_useDirectTcpField.getChecked() ? ";deviceside=true" : "");

where _serverip is my server address, _PORT is the port number _useDirectTcpField is my checkbox.

the deviceside=true parameter is what specifies the use of directTCP instead of MDS service.

you can find more information in JDE Version 4.x (pg 88 of 4.1 volume1)

if you have any questions just ask!

Lharts
   
  (#19 (permalink)) Old
lharts Offline
Knows Where the Search Button Is
 
Posts: 25
Join Date: Jun 2005
Model: 7230
Default 07-31-2006, 04:04 AM

here is a link to A VERY USEFUL thread that can provide you with further information.

www.blackberryforums.com/showthread.php?2185

let me knwo how you get on.
   
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




Wallpaper Megaplex for BlackBerry


Copyright © 2004-2008 BlackBerryNews.com, BlackBerryFAQ.com, BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of Research In Motion Limited.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.1