BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 11-11-2005, 09:08 AM   #1
fbrimm
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Question Socket connection

Please Login to Remove!

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
Offline  
Old 11-11-2005, 11:40 AM   #2
fbrimm
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Default

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.
Offline  
Old 11-16-2005, 01:36 AM   #3
ecarmody
Thumbs Must Hurt
 
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 9800
Carrier: AT&T
Posts: 82
Default

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
Offline  
Old 11-16-2005, 08:43 AM   #4
fbrimm
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Default

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
Offline  
Old 11-16-2005, 12:07 PM   #5
ecarmody
Thumbs Must Hurt
 
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 9800
Carrier: AT&T
Posts: 82
Default

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
Offline  
Old 11-16-2005, 01:52 PM   #6
fbrimm
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Default

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();
                
        }
Offline  
Old 11-16-2005, 02:48 PM   #7
ecarmody
Thumbs Must Hurt
 
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 9800
Carrier: AT&T
Posts: 82
Default

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.
Offline  
Old 11-18-2005, 11:27 AM   #8
fbrimm
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Default

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.
Offline  
Old 11-18-2005, 11:42 AM   #9
ecarmody
Thumbs Must Hurt
 
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 9800
Carrier: AT&T
Posts: 82
Default

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
Offline  
Old 11-18-2005, 03:23 PM   #10
fbrimm
Thumbs Must Hurt
 
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Posts: 144
Default

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.
Offline  
Old 11-20-2005, 02:10 PM   #11
ecarmody
Thumbs Must Hurt
 
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 9800
Carrier: AT&T
Posts: 82
Default

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
Offline  
Old 11-24-2005, 05:02 AM   #12
lharts
Knows Where the Search Button Is
 
Join Date: Jun 2005
Model: 7230
Posts: 25
Default

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.
Offline  
Old 12-17-2005, 01:52 AM   #13
abhay
New Member
 
Join Date: Dec 2005
Model: 7290
Posts: 1
Default socket connection

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
Offline  
Old 12-17-2005, 09:19 AM   #14
lharts
Knows Where the Search Button Is
 
Join Date: Jun 2005
Model: 7230
Posts: 25
Default

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!!
Offline  
Old 07-18-2006, 03:39 PM   #15
arcadiop
New Member
 
arcadiop's Avatar
 
Join Date: Jun 2006
Model: 7100r
Posts: 9
Default

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.
Offline  
Old 07-21-2006, 03:47 PM   #16
lharts
Knows Where the Search Button Is
 
Join Date: Jun 2005
Model: 7230
Posts: 25
Default

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
Offline  
Old 07-30-2006, 01:55 PM   #17
eye_s
New Member
 
Join Date: Jan 2006
Model: 7100i
Carrier: Sprint/Nextel
Posts: 1
Default

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.
Offline  
Old 07-31-2006, 03:58 AM   #18
lharts
Knows Where the Search Button Is
 
Join Date: Jun 2005
Model: 7230
Posts: 25
Default

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
Offline  
Old 07-31-2006, 04:04 AM   #19
lharts
Knows Where the Search Button Is
 
Join Date: Jun 2005
Model: 7230
Posts: 25
Default

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.
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


National Instruments Mainframe Chassis - NI-PXIe-1071 w/Warranty picture

National Instruments Mainframe Chassis - NI-PXIe-1071 w/Warranty

$690.00



Tektronix TM503 3 Bay Mainframe With FG 503, DM 502, PS 503 A Modules 120V AC picture

Tektronix TM503 3 Bay Mainframe With FG 503, DM 502, PS 503 A Modules 120V AC

$169.64



Chroma 6312A DC Electronic Load Mainframe **FOR PARTS ONLY, POWERS ON** picture

Chroma 6312A DC Electronic Load Mainframe **FOR PARTS ONLY, POWERS ON**

$150.00



Agilent E1301B Mainframe  9-slots with multimeter, totalizer, and relay muxes picture

Agilent E1301B Mainframe 9-slots with multimeter, totalizer, and relay muxes

$200.00



NEWPORT 8800 PHOTONICS TEST SYSTEM MAINFRAME picture

NEWPORT 8800 PHOTONICS TEST SYSTEM MAINFRAME

$499.99



MT9810A ANRITSU OPTICAL TEST SET MAINFRAME picture

MT9810A ANRITSU OPTICAL TEST SET MAINFRAME

$500.00







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.