Ways to do network programming in Cocoa - ios

It seems like there a bunch of ways to do networking in Cocoa: Webkit, NSUrl, CFNetwork, BSD Sockets. Is there any other APIs/Frameworks that are commonly used for networking? I'm trying to understand all the ways to do networking in Cocoa and learn each one's strength's and weaknesses.
As a related question, why would anyone use CFSocket? It seems that most things can be done with NSUrl or BSD Sockets. Is CFSocket commonly used in practice?

You can watch the WWDC videos Network Apps for iPhone (Part 1, Part 2) and Networking Best Practices where they suggest to use NSURLConnection for HTTP and HTTPS, the CFSocket/CFStream/NSStream family for other TCP networking, and of course WebKit if you just intend to render web content. They advice against using the low-level BSD sockets, unless you're writing a server. The higher level frameworks you use, the more things are taken care for you (from DNS resolution to cellular network management, authentication, encryption, run loop integration...) and the more it is integrated to the rest of the Cocoa framework.

For iOS, the best networking suite is AFNetworking. It is being actively developed and has everything you should need to work with any network for your project.

Related

Apple Secure Transport API is deprecated, what alternatives are there

Hi according to this the API is deprecated and considered legacy. It is not specific about when it will be removed. They recommend using Network, though it doesn't have a low-level API for alternative transports/physical layers.
I plan on using it for securing Bluetooth communications (like a BLE Uart thing), which means the API should not be dependent on network transports. Secure Transport fits this bill.
Is it okay to use this for future-safe developments?
Is there an alternative that will support something with an obscure transport layer (like BLE)?
I've looked at Swift-nio and its children, and it looks like it may work when overriding Channel etc, though it is more geared toward network transports.

IOT with MEAN - Together

MEAN stack and IOT are the current trending hot topics. Can these two be used together? If yes then in what way?
How can these technologies be used together?
Sweta.
By saying MEAN.js you are including things that are not strictly in the IoT terrain. Angular for example has little to do with anything.
On the web front end you need to implement a javascript library like Paho.js that will use the MQTT protocol to connect to a broker and start aggregating messages from connected devices.
Express has little to do as well as you are not exposing a Restful interface but connecting low level through a broker. A good solution in Node.js is Mosca.
Mongo is good for dumping data from devices.
I have written a tutorial using Node.js and iOS so have a look and you might find it interesting.
Mean stack is the combination of the frontent web frameworks like angularjs,emberjs,knockoutjs,backbonejs , javascript's backend server called nodejs and using the mongodb at top. so using these frameworks and library will make a mean stack developer.
IoT pronounced as Internet of things. iot is recently used for connected electronics devices .basically it is a form of running your program inside the electronic chip and mostly trying to connect the devices.making control on devices using the programmed chip. there are separate IDE's are avaialble for developing and testing the programme on embeded chip.
you can use angularjs as a frontend(making your GUI) for your IoT'S application.
Yes, you can.
As a fact is has been done before. And in other frontend frameworks too. Here there is an example for home automation.
You can find even a yeoman generator for such projects here.
[Disclaimer: I work here] Netbeast started managing devices and creating a system of plugins on top
of a MEAN app and RESTful communications. (Now we use a MERN
stack, with react and MQTT over websockets to control networks and
update values in real time.)
To mention other places where you can find examples of current projects using MEAN to run IoT networks I encourage you to join angular, arduino and raspberry communities, as well as taking a tour over producthunt.com, hackster.io and other maker sites such as the previously mentioned Netbeast forum.
Yes you can make an IoT platform with the MEAN stack. Typically the sensors are low cost sensors and are constantly transmitting small amounts of data in MQTT or TCP protocols. With Node.js you can write, servers for such applications very easily.
Mongo is useful if you have unstructured data, which could happen if you work with multiple sensors. If you don't need unstructured data structures, SQL is sufficient.
All the data that you get from devices, finally needs to be consumed via applications. Express and Angular are great platforms to manage web applications.
You can read a little more about IoT platforms in MEAN at http://blog.yatis.io/scalable-iot-platform-mean-stack/

What are the differences between MKNetworkKit and AFNetworking?

I'm running some test on those two networking framework: MKNetworkKit and AFNetworking. And I am seeing that it is not easy to see the differences between the two libs. What are the major differences between the two?
MKNetworkKit:
Cache on disk included.
Frozen operations (offline requests can be queued to be executed when the network is back).
More lightweight.
AFNetworking:
More users and contributors.
Better documentation (clearer and more accessible).
UIImageView+AFNetworking for lazy image loading (possible in MKNK, but more painful).
Standard (Apple-like) coding style.
Better leverage of SDK objects (NSCoding compliant).
Great variety of extra features and extensions (e.g. network reachability, streaming multipart form requests, backgrounding support, etc).
Has a nice project logo. ;-)
Anything else?

How much difference will using HTTP or TCP make?

I am making a gamer server for an ipad,iphone application.
It is a two-player card game but there could be multiple games going on between any two players.
After going through a lot of forums and blogs, I decided to use nodeJS and mongo-db combination.
Now I am new to both but I have time to learn these things and I have a decent amount of experience in JS.
What I am not sure about is, If my client side is iOS and objective-C stack.
What could be the best approach among TCP,HTTP with REST and WebSockets considering,
Reliable libraries avaliable.
complexity level
performance
In case you feel that I should not be using nodeJS in the first place itself, please point me towards the right direction as I am yet to start.
If you're considering using iOS, WebSockets are a no-go -- I'm sure you don't want to make your whole game out of a single big UIWebView.
TCP: well, that's an interesting question. Plain TCP has generally a smaller overhead than HTTP because of no avket headers/etc. are required, but implementing your own protocol is a much greater challenge that should be mecessary for writing a game and you'll end up with the same pitfalls that of HTTP with regard to speed/performance. Also, the BSD sockets API with which you can do TCP networking on Unix is not obvious to use at first glance. However, if you decide to use TCP, here's my OO wrapper for the API: http://github.com/H2CO3/TCPHelper
HTTP: ypu should probably choose it. It has a great history, it's a very mature protocol, and there are quite a few high quality C and Objective-C libraries out there for it. Cocoa (Touch) has the NSURL* kind of Objective-C classes and you also have libCURL for C.
On server side, you also might want to prefer HTTP as modern servers implicitly and automagically support it and you don't have to mess with the protocol to send a message, instead you simply say
<?php echo "Hello World"; ?>
Again, if you want to dig deeper, you can use WebSockets at server side if you deicde to use plain TCP.
I hope this will help.

Managing Cisco programmatically; Telnet vs SNMP? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I was recently approached by a network-engineer, co-worker who would like to offload his minor network admin duties to a junior-level helpdesk tech. The specific location in need of management acts as an ISP for tenants on its single-site property, so there's a lot of small adjustments being made on a daily basis.
I am thinking it would be helpful to write him a winform app to manage the 32 Cisco devices, on-site. I'd like to initially provide functionality which could modify access control lists, port VLAN assignments, and bandwidth limitations per VLAN... adding more to the list as its deemed valuable.
My initial thought was to emulate a telnet session with the network device; utilizing my network-engineer's familiarity with the command-line / IOS interaction. Minimal time would be required to learn Cisco IOS conventions, myself.
Though while searching for solutions, it appears that most people favor SNMP. That, or, their specific circumstances pushed them in the direction of SNMP.
I wanted to know if I've overlooked an obvious benefit of SNMP. Should I be using SNMP? Why or why not?
SNMP is great for getting information out of a Cisco device, but is not very useful controlling the device. (although technically, you can push a new config to a Cisco IOS device using a combination of SNMP and TFTP. But sending a whole new config is a pretty blunt instrument for controlling your router or switch).
One of the other commenters mentioned the Cisco IOS XR XML API. It's important to note that the IOS XR XML API is only available on devices that run IOS XR. IOS XR is only used on a few of Cisco's high end carrier class devices, so for 99% of all Cisco routers and switches the IOS XR XML API is not an option.
Other possibilities are SSH or HTTP (many Cisco routers, switches, AP, etc. have an optional web interface). But I'd recommend against either of those. To my knowledge, the web interface isn't very consistent across devices, and a rather surprising number of Cisco devices don't support SSH, or at least don't support it in the base license.
Telnet is really the only way to go, unless you're only targeting a small range of device models. To give you something to compare against, Cisco's own CiscoWorks network management software uses Telnet to connect to managed devices.
I wouldn't use SNMP, instead look at a little language called 'expect'. it makes for a very nice expect/response processor for these routers.
I have done a reasonable amount of real world SNMP programming with Cisco switches and find Python on top of Net-SNMP to be quite reasonable. Here is an example, via Google books, of uploading a new Cisco configuration via Net-SNMP and Python: Cisco Switch Upload via Net-SNMP and Python. I should disclose I was the co-author of the book referenced in the link.
Everyone's milage may vary, but I personally do not like using expect, and prefer to use SNMP because it was actually designed to be a "Simple Network Management Protocol". In a pinch, expect is ok, but it would not be my first choice. One of the reasons some companies use expect is that a developer just gets used to using expect. I wouldn't necessarily chock up bypassing SNMP just because there is an example of someone automating telnet or ssh. Try it out for self first.
There can be some truly horrible things that happen with expect, that may not be obvious as well. Because expect waits for input, under the right conditions there be very subtle problems that are difficult to debug. This doesn't mean a very experienced developer can't develop reliable code with expect, but it something to be aware of as well.
One of the other things you may want to look at is an example of using the multiprocessing module to write non-blocking SNMP code. Because this is my first post to stackoverflow I cannot post more then one link, but if you google for it you can find it, or another one on using IPython and Net-SNMP.
One thing to keep in mind when writing SNMP code is that it involves reading a lot of documentation and doing trial and error. In the case of Cisco, the documentation is quite good though.
SNMP isn't bad but it may not be able to do everything you need it to do. Depending on the library you use and how it hides the details of interacting with SNMP you may have a hard time finding the correct parts of the MIB to change and even knowing what or how to change them to do what you want.
One reason not to use SNMP is that you can do all the configuration you need using the IOS XR XML API. It could be a lot easier to bundle up the commands you want to send to the devices using that than to interact with SNMP.
I've found SNMP to be a pain for management. If you just need to grab a little data it's great; if you need to change things or use if heavily it can be very time consuming. In my case I'm comfortable with the CLI so a Telnet approach works well. I've written some Python scripts to perform administrative tasks on various pieces of network gear using Telnetlib
SNMP has quite a significant CPU hit on the devices in question compared to telnet; I'd recommend telnet wherever possible. (As stated in a previous answer, the IOS XR XML API would be nice, but as far as I know IOS XR is only deployed on high-end carrier grade routers).
In terms of existing configuration management systems, two commercial players are HP Opsware, and EMC Voyence. Both will probably do what you need. I'm not aware of many open source solutions that actually support deploying changes. (RANCID, for example, only does configuration monitoring, not pre-staging and deploying config changes).
If you are going to roll your own solution, one thing I would recommend is sitting down with your network admin and coming up with a best-practice deployment model for the service he's providing (e.g. standardised ACL, QoS queue, and VLAN names; similar entries in ACLs that have the same function for different customers, etc.). Ensure that all the existing deployed config complies with this BP before you start your design, it will make the problem much more manageable. Best of luck.
Sidenote: before you reinvent the wheel writing another service provisioning system/network management system, try looking for existing ones. I know quite a lot of commercial solutions of various degrees of flexibility/functionality, but I am sure there are quite a lot opensource ones.
Cisco has included menu options for helpdesk applications. Basically you telnet to the box and it presents a nice clean menu (press 1, 2, 3). For more info check this link:
http://www.cisco.com/en/US/docs/ios/12_2/configfun/command/reference/frf001.html#wp1050026
Another vote for expect.
Also, you don't want to allow configuration of your firewalls via either telnet or SNMP - ssh is the only way to go. The reason is that ssh encrypts its payload, and will not expose the privileged management credentials to potential interception.
If for some reason you cannot use ssh directly, consider connecting up an ssh-enabled serial console server to the firewall's console port and configuring it that way.

Resources