Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Socket problem, write does not work

Hi all.

I'm currently trying things out with sockets.
This is my code: http://pastie.org/1001029

As you can see I first open the socket.
Then I try to write something to it, but when I do, I get no "Data received" in my debug log. It should, since the event listener logs that when something is read. This means nothing is sent. So how can I fix this problem?

Thanks in advance

— asked June 11th 2010 by Doney den Ouden
  • iphone
  • listen
  • mobile
  • socket
  • write
1 Comment
  • The problem is that you're assuming that the socket automatically connects to itself. The way you've configured it, your socket "listens" for incoming connections, but does not connect to anything. You essentially have one endpoint of a socket system. The other endpoint is made up of a "connecting" socket, which connects to the listening socket and allows them to transfer data to each other. In the Kitchen Sink tests, we use the device as the listening endpoint and a raw telnet terminal to emulate a connecting socket.

    You are also using the INADDR_ANY token incorrectly. If you would like to test the socket system within a single page context on the device, to ensure that your listeners work, you can try the following code:

    http://pastie.org/1004116

    Please note that sockets are a very complicated feature and it is strongly recommended that you read all available documentation, and familiarize yourself with the basics of the BSD socket system, before attempting to use them. Improper use of sockets can hog system resources, cause crashes, or even create security flaws in your application that may lead to rejection.

    — commented June 14th 2010 by Stephen Tramer

0 Answers

The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.