I am getting pretty frustrated, i have an tcp server running on my mac where i have a couple of devices hooked up to. I wanted to have my iphone connected to it so i can run som commands from my iphone directly to my mac # home.
The tcp client for my iphone works pretty good except for one fault, it seems like it doesnt clear up the outputstream for each string i send. Here is an example of what i am having problems with
I type in "Start my browser" on my iphone client and hit send
The message pops up on my mac, everything ok so far
I want to send another command from my iphone and type "B" and hit send
The output on the iphone will then be "Btart my browser"
It seems as it keeps the previous string in cache or something.
Does anyone have any sugestions? I would appreciate all help, if you need to see any of my code please post an message saying so and i will have it posted.
Without any code I can only guess, but this looks like a bug in your code that handles the string input. In case you are using a NSMutableString / NSMutableData to store your input, make sure you clear that input after accepting a command. It now looks like you just overwrite the beginning without actually erasing it first.
The source of the problem was that my server software not emptying the datastream. When I emptied the stream on the server side, it worked perfectly.
Related
I have an iOS app that establish a peer-to-peer connection through Bonjour/NSNetService. (based on the WiTap sample code)
In some cases, both devices won’t receive data anymore after a few seconds while they are still able to write data out (i.e. without an error being reported).
The data written to the NSOutputStream never makes it to the NSInputStream of the other side.
The strange part is that sending and receiving works right after the connection is established. It seems to go bad after a few seconds.
If I set includesPeerToPeer = false it is not happening anymore. Does anyone having the same issue? I need to use peer to peer because is required to use bluetooth.
Thanks
My first guess would be that you're writing data to the stream before you get a stream event telling you that it is ready to accept more data.
If that isn't the problem, then either it's a bug in your code (which you haven't posted any of) or... well, it is possible that the class in question still doesn't work correctly. See:
https://developer.apple.com/library/ios/qa/qa1546/_index.html
If that's the case, you might have to drop down to Core Foundation briefly.
Currently, i'm working with HLK-RM-04 wifi to UART module. I'm using this in server mode. I've connected this module(tx/rx) to my PIC16F887. Connections are fine and I can able to transmit and receive data.
All i'm doing here is giving a html request from a browser/web client, and i'm expecting my data(responded from my MCU) to be displayed in browser. But i'm not getting it properly. Sometimes it works in right way, but most of the time if displays some junk value.
To analyze from MCU side, i tapped my MCUs Tx pin and connected to PC COM port. Yes, it seems it works perfect. I can able to see my data in hyper terminal, what i'm transmitting from MCU.
So to analyze from PC side, I used a free web-sniffer. There I can see data received was junk at sometimes. (Pls refer images) I couldn't able to guess whats wrong ?
Data sent to wifi module from MCU was right, but data sent from wifi module as wifi frames are bad ?
Is that any way to analyze further ?
Expected response - 1 out of 5 request wins:
bad response 2:
I don't remember when I was using HyperTerminal for the last time and I am not sure will it show whitespace characters (if I remember there is such settings).
One of the things that I would try is to install serial port sniffer or some advanced terminal (like Realterm) and verify that there is no some junk in form of white space characters that are hidden in HyperTerminal.
I want to make an app which compiles Swift code, so how can I use a website named www.swiftstub.com or any similar website to retrieve the output of the code? I want my app to have a simple UITextView in which the user can type the code. If a UITextView cannot be used, what can be used?
I want my app to send the code typed to this website, and then retrieve the output back and display it. How can this be done? Thanks!
Make an app that sends text to a server.
Have the server compile this code, run it, and capture the output.
Send this output back to the app.
Have the app display the output.
This is an extreme oversimplification, there are lots of things to consider, but these are kind of the big sections of whats there to to. You need to understand very well on the app side: UI and networking, and on the server side: triggering a compilation of text, capturing that output (command line, maybe Swift or Python can help you here) and HTTP(S) responses and requests (or sockets, even harder).
This does not sound like an easy task, so you are very courageous.
Build all components locally:
App:
- write an app with a textView and a button, and on the tap of that button, save the output to a textile. This is to avoid any networking complications at this point, later, instead of saving, you would send this to a server.
Server: (just build the things on your computer)
- write some script/program that can read in that textfile that was saved.
- Then you need to compile this code (lookup 'xcrun' on google) and capture the output. Save this output to a textile. Have your app load this file and display it.
The important thing to consider is the real server machine you will run this code on later: it has to be a machine that can compile, and execute Swift code. Currently, this means it has to be an OS X machine. This is hard to find, as most servers run linux, and there is no Linux Swift compiler yet.
Getting this to work would be a proof of concept: you can capture text from the app, you can grab this text and compile it, you can capture the output of the compilation, and you can have the app read that output and display it.
Once you've got this working, you would need to find a server that can do the compilation part, and run what you build to do that. Then you would need to write some code in your app that sends an HTTP request to your server containing this text, to which your server would respond with the output of that compilation.
As I said, this is a big undertaking, with lots of difficult parts and unexpected surprises, so don't expect this to be done in a couple of weeks, it will most likely be more like over six months.
Try to find someone who has experience on programming and setting up a server, that will really help you a lot.
I have weird issue running the last version of Raknet on iOS with Unity3D: I get CONNECTION_ATTEMPT_FAILED when trying to connect to the server.
Now let's me detail the issue:
he exact same Library connects fine when used in an ObjectiveC application, so the issue seems to be Unity3D related.
I already managed to pinpoint my issue to be located in Raknet reliability layer:
Apparently, during the last step of the connection process (when the connection handshake as been completed) the reliability layer of the server thinks that the ID_CONNECTION_REQUEST packet received from the client is an acknowledgment instead of a message. Therefore it doesn't answer. Ultimately after a few tries, (and a 10s timeout) the client fails with the CONNECTION_ATTEMPT_FAILED error.
Does anybody there as an idea? I will update the question when I manage to get more info.
Update
We are using Unity3D 5.1.1f1
We managed to find a workaround! See answer for more information. As the workaround doesn't tell us much about what really happened, I would gladly hear some C++/XCode/Unity/iOS/AppleLLVM6.1 experts around here explain what really happened.
The issue was that the Raknet header wasn't properly generated by the iOS client. Namely we were sending ACK messages in place of simple packets. The rest of the message was considered as garbage by the server and the packet was dropped. The client kept trying to send the corrupted handshake packet a few times before timeouting.
This doesn't tell us why, doesn't it? Apparently the serialize method of the class DatagramHeaderFormat wasn't called as it should have been when running Raknet in Unity (iOS). Something else (and I don't know what) was linked in place of this method and was filling the BitStream with a corrupted header.
I am quite sure that the serialize method wasn't called because printf calls from inside weren't displayed in the console.
We renamed DatagramHeaderFormat::serialize into DatagramHeaderFormat::serializeHeader and... voila, it works.
Now I only want to understand what did the compiler (and why).
I read some of the similar posts on this site that deal with what seems to be the same issue and the responses didn't really seem to clarify things for me.
My application works fine in the simulator. I believe I'm on Bold 9000 with OS 4.6. The app is signed.
My app makes an HTTP call via 3G to fetch an XML result. type is application/xhtml+xml.
In the device, it gives no error. it makes no visual sign of error. I tell the try catch to print the results to the screen and I get nothing.
HttpConnection was taken right out of the demos and works fine in sim.
Since it gives no error, I begin to reflect back on things I recall reading back when the project began. deviceside=true? Something like that?
My request is simply HttpConnection connection = (HttpConnection)Connector.open(url);
where url is just a standard url, no get vars.
Based on the amount of time I see the connection arrows in the corner of the screen, I assume the app is launching the initial communication to my server, then either getting a bad result, or it gets results and the persistent store is not functioning as expected.
I have no idea where to begin with this. Posting code would be ridiculous since it would be basically my whole app.
I guess my question is if anyone knows of any major differences with device versus simulator that could cause something like http connection or persistent store to fail?
A build setting? An OS restriction? Any standard procedure I may have just not known about that everyone should do before beginning device testing?
Thanks
Just providing the URL will not work. You will have to append some info after the URL to determine the transport method your HTTP connection will use. For instance http://example.com;deviceside=true will use DirectTCP (you might also have to supply APN information but that's saved on the device for my phone). http://example.com;interface=wifi will use wi-fi. On OS 5 there's a ConnectionFactory class that makes this a lot easier. Here's a link that goes into more detail.
This was a tough one for me!
As Jonathan said you have to put some parameters in the url to make it work on the device. You shouldn't do it by hand but use the ConnectionFactory instead.
As you may thing this would just make it work but it doesn't!
The real problem is that not the url has been altered because it has ;interface=wifi;deviceside=true in it (in my case). Depending on the webserver accepting your request this could broke the code.
A solution I tried and that works is try to happend a fake parameter like
&foo=true -> &foo=true;deviceside=true
This will result as a standard parameter for the webserver but your device would use it to driver your connection.
On the simulator this work without this extra code because behind it there is a BIS server for you. On the device (as in my case) there isn't because I'm using a development device unregistered and without SIM (just wifi).
Another point is that the HttpConnection class doesn't handle HTTP 302 Redirect and if you get one you have to handle it manually.
It's probably an issue with the APN not being specified. See my answer for this question for details:
video streaming over http in blackberry
I would make this a comment, but I think I don't have enough rep yet for that... So I'll just answer and hope this doesn't get hosed for just pasting in some links.
I've been working on this exact sort of networking issue on our app this past week, and it is indeed tricky as some others have pointed out. Here are two links which really helped us out using HTTP on different devices, especially older devices which do not provide ConnectionFactory.
http://supportforums.blackberry.com/t5/Java-Development/Connecting-your-BlackBerry-http-and-socket-connections-to-the/td-p/206242
The first one has some code examples, including demonstration of querying the system's ServiceBook and CoverageInfo classes to make a decision about what kind of connection will work.