socket connection problem

Hello

Here is my code to open a client-side socket connection to a server running on the vmware host I don't know there works well (the server):

#include
#include
#include
#include
#include

int _socket;
struct sockaddr_in name;

bool connect (char * ip, int port)
{
_socket = socket (AF_INET, SOCK_STREAM, 0);
If (_socket<>
{
Returns false;
}
struct hostent * host;
struct in_addr addr = {0};
addr.s_addr = inet_addr (ip);
Host = gethostbyaddr ((char*) & addr, 4, AF_INET);
Name.sin_family = AF_INET;    Name.sin_addr.s_addr = * ((unsigned long *)-> h_addr host);
Name.sin_port = htons (port);
If (bind (_socket, (struct sockaddr *) & name, sizeof (name)))
{
Returns false;
}
Listen (_socket, 1);
_socket = accept (_socket, 0, 0);
Returns true;
}

Connect ("127.0.0.1", 44444);

When you call the connect() method is block on accept() (EEG open Server before the client does). So, I need to know if the question is:

1_ on my customer code.

or

2_ vmware cannot connect to the host computer using the address of the local host computer.

(or even both)

You will appreciate all help.

Thank you.

After a lot a work around, I realize that the last three

Methods include the specified address and get ready to listen and

accept a connection from an unknown client. I mean, it's

create a server, that is why it stops on the accept() method.
For example, the code for one side of the client socket should look like this (or almost)

(similar):

bool open_connection (char * ip, int port)
{
_socket = socket (AF_INET, SOCK_STREAM, 0);
If (_socket<>
{
Returns false;
}
struct hostent * host;
struct in_addr addr = {0};
addr.s_addr = inet_addr (ip);
Host = gethostbyaddr ((char*) & addr, 4, AF_INET);
Name.sin_family = AF_INET;
Name.sin_addr.s_addr = * ((unsigned long *)-> h_addr_list host)

[0]);
Name.sin_port = htons (port);
If (connect (_socket, (struct sockaddr *) & name, sizeof))

(name)) )
{
Returns false;
}
Returns true;
}

Then, from the host and the Simulator on a socket connection I

the same as that used for the loading of the appliction to it.
One thing: when I try to establish a connection when my computer

is connected to the internet both the binding and the connection,

the function failed.
@Mshom: when I tried to put the adapter to bridge the

Simulator cannot obtain an "ip address" ("get ip address... is written

Botton left on cone winder").
By the way, he thinks that all those of you who answer me.

Tags: BlackBerry Developers

Similar Questions

  • in the waking state socket connection problem

    Hi all.
    My app need update real-time security data, it should be able to run well even the switch of the PB in the waking state.
    The problem is that when PB passes to the waking state and more than an hour later, my application cannot send request for data to the socket server (initially he workd well), even when the PB get again enabled, the socket connection is also unnecessary.
    I did a test as follows:
    1, I added the "throttled" in the blackberry - tablet.xml
    2. I have add a few listiner event in the main class, but each of them can be fired in any time.

    QNXSystem.system.addEventListener(qnx.events.QNXSystemEvent.STANDBY,onDeactive);
    QNXSystem.system.addEventListener(qnx.events.QNXSystemEvent.ACTIVE,onActive);
    QNXSystem.system.requestResource(QNXSystemResource.NETWORKING);
    stage.addEventListener(Event.USER_IDLE,userIdle);
    stage.addEventListener(Event.USER_PRESENT,userPresent);
    stage.addEventListener(Event.ACTIVATE,onStageActive);
    stage.addEventListener(Event.DEACTIVATE,onStageDeactive);
    

    3, I put a clock to save information in / shared folder.it worked well in the waking state.

    Thanks for any response.

    Hello.
    I'm a developer of instant messaging which is connected to the door via socket. What I can tell you for sure I you need to use:
    normal
    That, to use SocketMonitor to ensure that connections are available, some WiFi routers can close idle connection event when U don't want to! If you need to reconnect in such cases.
    Please, feel free to ask for help more.

  • I have a problem when you try to receive data using the socket connection.

    Hello

    I created a socket connection between a pc (sever, win32) and a blackberry (client) and I have only two questions:

    -When I send a string to the sever I get the unexpected result, I doubt if it's a problem of encoding between platforms.

    -When I try to receive data, (an array of char as a string object), the customer demand freeze (drawing and management of events, so basically the main UI thread), even if I did all the stuff of connection in a separate thread, until I have shut down the server and also no data is received.

    I left the codes below and would assess any response from you.

    C++, win32 console application:

    SOCKET _Socket;

    int _tmain (int argc, _TCHAR * argv)

    {

    If (start_sever (_socket)) {}

    char r_msg [26];

    recv (_socket, r_msg, 26, 0);

    std::cout< "receive="" :="" "="">< r_msg=""><>

    char * s_msg customer = 'welcome ';

    Send (_socket, szMessage, strlen (S_MSG), 0);

    std::cout< "send="" :="" "="">< s_msg=""><>

    Sleep (500);

    Shutdown (_socket, SD_SEND);

    closesocket (_socket);

    WSACleanup();

    } else {}

    std::cout< "cannot="" initialize="">< std::endl="">

    }

    System ("pause");

    return 0;

    }

    BOOL start_sever (socket) {}

    WSADATA WsaDat;

    If (WSAStartup (MAKEWORD (2.2) & WsaDat)! = 0)

    {

    std::cout<"WSA initialization="">

    WSACleanup();

    System ("pause");

    Returns false;

    }

    Socket = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);

    if(Socket==INVALID_SOCKET)

    {

    std::cout<"Socket creation="">

    WSACleanup();

    System ("pause");

    Returns false;

    }

    SOCKADDR_IN serverInf;

    serverInf.sin_family = AF_INET;

    serverInf.sin_addr.s_addr = INADDR_ANY;

    serverInf.sin_port = htons (8888);

    If (bind (Socket,(sockaddr*) (& serverInf), sizeof (serverInf)) == SOCKET_ERROR)

    {

    std::cout<"Unable to="" bind="">

    WSACleanup();

    System ("pause");

    Returns false;

    }

    Listen(Socket,1);

    SOCKET TempSock = SOCKET_ERROR;

    std::cout< "build="">

    while(TempSock==SOCKET_ERROR)

    {

    std::cout<"Waiting for="" incoming="">

    TempSock = accept (Socket, NULL, NULL);

    }

    Socket = TempSock;

    std::cout<"Client>

    Returns true;

    }

    Platform of Java for blackberry:

    public class Bush extends form {}

    -my current ipv4 address is set by default to avoid reset at each test

    TextField ip_text_field = new TextField ("IP address:", "192.168.65.1");

    -the server is waiting for any connection to this port ("8888")

    TextField port_text_field = new TextField ("Port:", "8888");

    ButtonField go_button_field = new ButtonField ("Connect", Field.FIELD_HCENTER) {}

    protected Boolean invokeAction (int action) {}

    UiApplication.getUiApplication () .invokeLater (new Runnable() {}

    public void run() {}

    try {

    open_connection();

    }catch (System.Exception e) {}

    e.printStackTrace ();

    Dialog.Alert (e.getMessage ());

    }

    }

    });

    return true;

    }

    };

    public Socket() {}

    Super ();

    setTitle ("[taking sample]");

    Add (ip_text_field); ip_text_field.setMargin (20, 0, 0, 0);

    Add (port_text_field); port_text_field.setMargin (30, 0, 0, 0);

    Add (go_button_field); go_button_field.setMargin (30, 0, 0, 0);

    }

    public Boolean onClose() {}

    this. close();

    return true;

    }

    _Con StreamConnection;

    DataInputStream _in;

    OutputStreamWriter _out;

    public Sub open_connection() throws Exception {}

    _CON = (StreamConnection) Connector.open ("socket: / /" + ip_text_field.getText () + ":" + port_text_field.getText () +)

    » ; deviceside = true; interface = wifi");

    this.add (new TextField ("", "connected successfully to Server"));

    _in = _con.openDataInputStream ();

    _out = new OutputStreamWriter (_con.openDataOutputStream ());

    String msg = "Welcome to customer \r\n";

    _out. Write (MSG);

    String r_msg = _in.readUTF ();

    this.add (new TextField ("read from sever:", r_msg));

    _out. Flush();

    _in. Close();

    _out. Close();

    _CON. Close();

    this.add (new TextField ("", "data has been changed"));

    }

    }

    Thanks for your help.

    You treat on the thread of events.

    You have the following code:

    UiApplication.getUiApplication () .invokeLater (new Runnable() {}

    public void run() {}

    try {

    open_connection();

    .....

    Now invokeLater essentially tells the operating system that the associated executable must be run on the event Thread.  You need start a separate Thread.  Extend this Thread, add your code in the run() method, and then start the Thread with start(). (not run()).  Then you must run the networking of processing on a separate Thread.

    This will cause you problems updating the user interface.  Take a look at this help:

    http://supportforums.BlackBerry.com/T5/Java-development/update-a-screen-on-the-main-event-thread/TA-...

    Printing, this means that invokelater a separate Thread is a common misconception.  I recommend you to look at this:

    http://supportforums.BlackBerry.com/T5/Java-development/what-is-the-event-thread/Ta-p/446865

    In addition, I recommend that you take a look at the socketDemo which must be included as a sample-, otherwise you can find it on github:

    https://github.com/BlackBerry/JDE-samples

  • Problems with 9000 device establishing a socket connection?

    Edit again: still a problem, see Update 2 to end...

    My app works fine on 4.3 & 4.5, device and Simulator. Also works very well in the 4.6 Simulator. However, on the bold new we just acquired today, I can't do the blackberry establish a socket connection. As far as I can tell a call to Connector.open which has the form:

    String connUrl = "socket://:;deviceside=true";StreamConnection sc = (StreamConnection) Connector.open(connUrl);
    

    .. will never return! I set breakpoints after him in the file and I get nothing. There is no sign of a connection through to the other end. I put a breakpoint on the line with Connector.open so I know is to be worn, but if I click on 'no more' control is never returned to the jde debugger.

    I realize in Application 4.6 permissions have been moved around, but I've set manually the application has permission to connect to the internet. I tried to connect to a server, I know that the blackberry can access (e.g. www.google.com), I expect this to cause then an exception more than my application is obviously not HTTP... but nothing! No indication the Connector.open never call does not return. No exception seems also to be thrown, ControlledAccessException or other... can someone guess what might be happening here? It seems that it is a fundamental thing to do, I don't see what could have changed. My thread Manager program is still running behind all that (I see his messages to regular use of ram) isn't as all users of the application are overwritten or anything.

    My request is signed, I checked several times. I can also access the internet as usual from the blackberry browser. It is also interesting to note that, on the debugger to connect to the device, told me debugging information are missing about two - net_rim_cldc and net_rim_os modules if I remember correctly. Then, he said because of this "many debugging features will not work properly", but as far as I can see, willing or not, debug this connection is simply not be established, and yet no exception or anything is up. The above code is surrounded by try/catch that will catch java.io.IOExceptions and ControlledAccessExceptions, among others, but none of this code is already hit. And surely if it was some type of more exotic exception that I have no intention, I would like to at least get a popup on the screen tell me about an uncaught exception?

    Help would be greatly appreciated!

    UPDATE: standard Version, as soon as I had finished my half hour trying to get this thing to work and then wrote a post about the epic forum, he begins to work. Perfectly as I can tell. I guess it could have been a little temporary bad service from my supplier... Oh well anyway we are all good now...

    UPDATE 2: it appears when wifi connections aren't a problem, but if I turn off wifi problem remains. Any ideas?

    How long did you wait for an exception?  It must expire after 2 minutes if it is unable to connect.  Which way you make the connection?  You use the deviceside parameter?

    The BlackBerry has been activated on a BlackBerry Enterprise Server?  You have completed the information under Options, Advanced Options, TCP APN?  The BlackBerry shows 3G on the home screen (capital G)?

  • Maintenance of the Socket connections alive

    Hello developers,

    Please, I have problems to perpetuate a socket connection in my application for a long time. It seems to disconnect after a short (2 minutes) while especially if he's inactive.

    It happens that I have write an application with a Chat feature and for that, that I keep a socket connection Alive for the life - tme of my application. I tried stuff like Ping Server every minute, but then this is a leak of resources (Blackberry). Push BlackBerry is not an option (as I have other clients other than BB devices).

    Please someone know how I can fix this or suggest a different way to go about this?

    I agree with previos answering machine. The problem you have is push RIM invented.  I'm not aware of a way around that. If you cannot use the pusher, then you will have to keep alive and if your app will suffer battery drain and possibly additional costs related to data traffic.

    Some people have used email instead of push as a wau to notify the application that there is something to it: this requires a listener e-mail in the application process and eliminate these notification emails.

    If you do not use a living message of keep, then I think this quesiton becomes useless:

    «How I even the difference between blackberry...» »

  • Socket connection in the Simulator with MDS, but not on the curve

    Hello

    Working on an application using socket connections.

    SOC = (SocketConnectionEnhanced) Connector.open ("socket: / /" + address.ip_number + ":" + address.port_number + ";") deviceside = true");

    Proceed to use a DataInputStream and DataOutputStream to communicate.

    The server works, can transmit very well with the Simulator, but also another curve (not same model). (There is a small chance that deviceside = true has not been passed as a parameter when we tested on the curve, which would go through BES? This is probably still there however).

    IMHO, this means the places that the question could be one) how the code is implemented on the client phone or b) phones or their settings (have 4 curve 8530 s on the same CDMA network).

    -These phones have already activated in the last days, is there the chances that something is missing from the service book to allow socket connections? (I doubt that what I downloaded messenger ping I assume uses taken... and everything is fine).

    No authorization application that I put?

    Ideas! Please let your mind flow. Thank you!

    To all those who might find this thread after encountering the same problem:

    The issue was with the DataInputStream... available() was ALWAYS return zero, even if there are more bytes to read. This is our 8530 s curve 4 tests phones. Tried on another curve and "BOLD" and they did not have this problem.

    Use available() stopped and tried reading for much bigger than one of our packages will be (5000 bytes).

    Have some phones to test with 5.0.0.337 that they would not work with that.

    After the 5.0.0.1000 they all work perfectly.

    I read somewhere that the available() issue has to do with J2SE-> J2ME problems, something on a wrapper. This problem exists (or existed) with TSL/SSL apparently (sorry I can't find the thread I get this info, if someone really wants to see him answer and I'll get the link in the history of my browser of laptops).

    Hope this helps someone!

    B

  • socket connection - a reward for $30

    I am building an application that uses the socket connection. When the application runs, my desktop, it works fine, however when it is running on a remote server, I get the security sandbox violation: "cannot load data from serverName.com:portNumber."

    There is another application on the Adobe (posted by Josh Tynjala) lab that people have the same problem: http://www.zeuslabs.us/archives/6/connecting-to-aim-with-actionscript-3-sockets/

    Josh's response was: "you need to run the SWF to a location on your computer."

    Its application works well at the local level, but when I upload it to a remote server, I get: "cannot load data from aimexpress.oscar.aol.com:5190." Is it possible to get the socket connection to work on a remote server and not only on the desktop?

    I'll give you $30 (using western union or paypal) if someone can get Josh Tynjala application to work on the remote server.

    The file XML cross was placed in the wrong place, it works fine now.

  • AppStore connection problem!

    Hello

    I'm running a 21.5 "iMac with OS X El Captan 10.11.5. My problem is that I am not able to connect to iCloud and the App Store on my Mac.

    The error I get is "there was an error connecting to server Apple ID"

    The same username and password works perfectly well on the site of iCloud, my app store on the iPhone and the iPad, but not on Mac.

    What is the way my iMac communicates via the internet? We have a firewall. And oh, the software update for El Capitan is downloading as I type; He didn't even ask for IDs, just started downloading automatically. The same thing happened yesterday with the updates listed on the tab Update on the app store - they have been is downloaded yesterday without asking my login details but it was a rare event; connection problems I described above took place during the last month or so.

    How can I fix?

    Thank you!!

    Try disconnecting all the services using your Apple ID on your iMac, iTunes, FaceTime, iMessage and try to sing.

    If you cannot connect to the iTunes Store - Apple Support

  • Connection problems can not connect I forgot my password I did ' get the confirmation email.

    Cannot connect connection problems I forgot my password I have request a Reset password but I did ' t get the confirmation email.

    Go through the logon process. When you enter your name / password
    should be a link I forgot the password. Site more to have that.

  • Why do I get "Connection problem" on my laptop, when I try to access my e-mail account Yahoo with the new version of Firefox?

    Since I updated firefox to 29.0.1 on my desktop, I can't access my account at Yahoo.com from my ASUS laptop. "Connection problem" appears when he tries to retrieve new messages. I received mail on the ASUS 12/03/13, but from now on I get this message and no new mail arrives at the ASUS.

    Some problems occurs when your Internet security program was set to trust to the
    a previous version of Firefox, but no longer recognizes your updated as version
    level of confidence. Now how do I solve the problem: to allow Firefox to connect to the Internet
    Once again:

    • Make sure your Internet security software is up-to-date (for example, you are using the latest version)
    • Delete Firefox to list your program of trusted or recognized programs, then add it again. For detailed instructions, see Configure the firewall so that Firefox can access the Internet.
  • Strange internet connectivity problem

    Hello!

    I'm having a connectivity problem I have never met before. I use a wireless router from Apple with internet cable.

    Yesterday, my computer would be is no longer in contact with my router wi - fi. I get a message that the network could not be attached (I ran the Diagnostics wireless, but it's a whole lot of sense to me empty files). However, I also have a Roku, and which IS connected to the WiFi without problem. I completely stopped and restarted the computer, no joy. Reset the modem and the router, no joy. Still works with Roku, not with the computer. But the weird part is, I have Optimum Online, which allows subscribers to log-in to its hotspots, and it worked! I am connected Optimum wi - fi network on my computer right now.

    So I don't know where is the problem! It is not the router, because this is related work with Roku and is not the computer, because it is connected and working with the Optimum hotspot. What gives?

    Try this!

    Go to the Apple menu > System Preferences > network

    Select a Wi - Fi connection in the sidebar and then click on the button "Advanced...". "in the lower right corner of the screen

    In the list of preferred networks, delete the name of your Wi - Fi network

    Click on the "OK" button to save that change and then 'apply' in the network preferences window.

    Now, go to the Applications folder > utilities > Keychain Access

    Make sure that "Login" keychain is selected and "All items" in the category is selected in the sidebar

    Use the search field to find items that Keychain with the name of your Wi - Fi network and remove

    Quit Keychain Access

    Now try and access your Wi - Fi network

  • Icloud connection problems

    Hi - I've changed my Apple ID a year ago.

    For these last days, I get messages saying: my Mac cannot connect with icloud and gives the e-mail address of old and obsolete, that I stopped using it a year ago. I ' ved checked my details with the system Apple ID. Everything is up-to-date. Checked the system does not recognize the old e-mail address or the password tied to it.  How to stop the message saying that there is a connection problem?  Thank you very much

    Can you go into System Preferences/iCloud and log out of the old ID? Then log in with the ID of the new?

  • connection problems with the version 6.18.0.106

    Hello

    I have Windows XP and I have always used an earlier version of Skype, but now the old version is retired and I can't use it. So I download the new version 6.18.0.106, but this one has a connection problems. Every 4 seconds, I am offline and then online again for 4 seconds. My connection is OK and my provider does not block Skype calls. Is there anyone who knows how to fix?

    Try to uninstall the latest version and install the older version of Skype 6.14.0.104:

    http://download.Skype.com/MSI/SkypeSetup_6.14.0.104.msi

  • Connection problems: Win7, Skype 6.14

    Hello

    I had connection problems since just after I did a windows update last night. (no idea if it's just a coincidence?)

    I read through several other posts here, tried reinstalling Skype several times (also re-installed an older version), checked the compatibility mode and still no joy. Oh, I restarted a few times too.

    I'm trying to connect using my Skype username and password (I don't have an account of ms) but the screen is just stuck there, it says signing in and the whirly thing (term techy lol) is just Dervishes round and round.

    I luuuurv my Skype, absolutely essential for me because I work from home, so I hope someone can help. PLEEEEASE :-)

    Thank you

    Try to uninstall the currently installed version and install the older version of Skype 6.9.0.106 using this msi installer:

    http://download.Skype.com/MSI/SkypeSetup_6.9.0.106.msi

  • LJ pro M177fw: eprint center connection problem

    Hello

    today I am trying to add my new printer to my eprint account, but I do not remember my pwd, so I want to co reset the password.

    By e-mail, I received a link

    http://h30495.www3.HP.com/reset_password/xxxxxxxxxxxxxxx

    but it didn't work, the Web server show this error:

    SERVER ERROR

    Oops! Only, something was wrong with our server.

    Try refreshing the page.

    I tried different browser and pc, but I can not reset my pwd.

    Is there a solution to this problem?

    Is the server down for ever?

    Thank you and best regards.

    Roberto

    Hey @Roberto_ITALY,

    Thanks for posting in the Forum from HP Support.

    I understand that you are unable to claim your HP Color LaserJet Pro MFP M177fw in your account ePrint Center due to a connection problem.  I would like to help.

    I don't see this particular error with password resets from time to time.  I have a workaround that can clear up this place for you:

    • Click here.  This will bring you to <www.snapfish.com >.  As the Snapfish site is linked directly with ePrint Center and HP connected, you can try to reset your password as follows - click the connection icon and then "forgot your password":

    • Enter the e-mail address that you use to connect to the ePrint Center and click on submit.
    • You should receive a message of automatic reset of password by email - the reset as expected before and then try to use this new password to Snapfish to connect downtown ePrint.
    • If this does not solve your problem of access ePrint Center, please call our Cloud Services to 855-785-2777. If you do not live in the United States / Canada region, please click the link below to get help from your region number.

      http://WWW8.HP.com/us/en/contact-HP/WW-phone-assist.html

    I hope this helps.  If my suggestion worked in your favor, feel free to give me a virtual h.o.t. by clicking on the 'Thumbs Up' icon below.

    Have a great day!

Maybe you are looking for