Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
dhivyamca86
Posts: 48
Registered: ‎06-30-2010
My Device: 9000

Bad socket Id Exception in Http connection

Hi,

 

         For every 1hr i'm trying to send an XML data to the server, when the device was connected with mobile network its working fine but when i try to connect with the server using WIFI it throws an exception as "Bad Scoket Id". 

 

Note: This issue was in one particular device. Device 9780

 

Plz any one help me to figure out this issue why its happening only on this device....

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Bad socket Id Exception in Http connection

What BlackBerry device software version are you testing on?  You can find this under Options, About on the BlackBerry Smartphone.

 

Does this happen constantly?  Are you able to browse over WiFi (turn cellular radio off to test)?  Can you provide a code snippet that shows how you are initiating the connection?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Contributor
dhivyamca86
Posts: 48
Registered: ‎06-30-2010
My Device: 9000

Re: Bad socket Id Exception in Http connection

Hi Thanks for ur help.

 

My device details,

1. OsVersion::6.0.0.448

2. PlatformVersion::6.5.0.136

 

This problem happening constantly. Whenever it connected with WIFI i'm Geting the exception as 'Bad socket ID'.

I can able to browse over WIF.

 

Code snippet:

public

intHttpConnection(Vector inParam)

{

Request requestObject =null;

intresponsecode = 0;

DataOutputStream os =null;

 

try

{

ServerURL instance =newServerURL();

String URL = instance.getServerURL() + getConnectionString();

StringBuffer response =

newStringBuffer();

log("URL in HttpConnection :: "+ URL);

HttpConnection _httpConnection =null;

try

{

_httpConnection = (HttpConnection) Connector.open(URL);

_httpConnection.setRequestProperty("Content-Language", "en-US");

_httpConnection.setRequestMethod(HttpConnection.POST);

os = (DataOutputStream) _httpConnection.openDataOutputStream();

requestObject = (Request) inParam.elementAt(0);

requestObject.getXML(os);

os.flush();

log("Response code in HTTP :: "+ _httpConnection.getResponseCode());

responsecode = _httpConnection.getResponseCode();

if (responsecode == HttpConnection.HTTP_OK)

{

InputStream inputStream = _httpConnection.openInputStream();

int ch;

 

while((ch = inputStream.read()) != -1)

{

response.append((

char) ch);

}

ServerURL sURL =newServerURL();

sURL.updateURL(response.toString());

}

os.close();

_httpConnection.close();

returnresponsecode;

}

catch(IOException e)

{

log("Exception in Http com :: "+ e.getMessage());

e.printStackTrace();

}

}

catch(Exception ex)

{

}

returnresponsecode;

}

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Bad socket Id Exception in Http connection

Are you including any parameters at the end of the URL (i.e. deviceside)?  What line of code is throwing the exception?  Are you able to reproduce the same behaviour with the httpdemo?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Contributor
dhivyamca86
Posts: 48
Registered: ‎06-30-2010
My Device: 9000

Re: Bad socket Id Exception in Http connection

yeah i'm including parameter interface=wifi at end of the URL. The exception was throwing at the line _httpConnection.getResponseCode(), While getting the response code.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Bad socket Id Exception in Http connection

Change:

log("Response code in HTTP :: "+ _httpConnection.getResponseCode());

responsecode = _httpConnection.getResponseCode();

to

responsecode = _httpConnection.getResponseCode();

log("Response code in HTTP :: "+ responsecode);

 

I suspect this might resolve your problem.

Contributor
dhivyamca86
Posts: 48
Registered: ‎06-30-2010
My Device: 9000

Re: Bad socket Id Exception in Http connection

No :smileysad: this not solved my problem.... Any other option is there to fix this issue.

Super Contributor
yogesh1984
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800

Re: Bad socket Id Exception in Http connection

can v connect wifi to simulator... 

Contributor
dhivyamca86
Posts: 48
Registered: ‎06-30-2010
My Device: 9000

Re: Bad socket Id Exception in Http connection

yeah. Its working fine in simulator and also in other devices. Only this problem is araised on the particular device which i mentioned above.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Bad socket Id Exception in Http connection

Can you confirm that in the original code:

log("Response code in HTTP :: "+ _httpConnection.getResponseCode());

responsecode = _httpConnection.getResponseCode();

 

the problem only happened in the second

_httpConnection.getResponseCode();

 

Regarding connecting WiFi in SImulator, yes you can.  Just go through WiFi Setup on the device and it will automatically find a built-in WiFi Service.  You are not really connecting to WiFi, but you are exercising your WiFi code and the WiFi transport code, on the SImulator.  It will still use whatever connection method your PC is using.