How can I make my iPad a TCP Socket Server? - ipad

Can anyone point me to an example or an explanation of how to get a server going on an iPad? I want to use TCP sockets and I've already downloaded the current AsyncSocket stuff but it's trickier looking than I thought. I've been researching but everyone talks about iOS as the client and some PC as the server. I would like to set up my iPad as a local server for a game I'm writing.

You can use the C socket api. Every valid C standard library is also valid in Objective-C. Here is a nice guide for programming sockets with C.

Related

P2P Connection with Sockets on iOS

I'm doing one university homework, where I need to make the Chinese Checkers game work via sockets.
I've followed this tutorial on raywenderlich and it seems easy setting up the streams, but in this tutorial its used a local server to intermediate the connection, and I don't know how to make a server, so I kinda need to make the connection be p2p, but i don't know how I'm going to discover the IP and Port the app is running on iOS.
Personally, it's the first time I've seen about sockets and I really need help.
If you guys can teach me how to connect 2 apps to each other directly USING SOCKETS (otherwise my teacher won't accept it) or point me where I can learn how to make a simple server for this matter it would be really great.
P.S: I know I can use GameKit, MultipeerConnectivity and etc for it, but I'm really obligated to use sockets :/

Building iOS Native App using WebRTC

I'm searching for 4 days, but can't get it. I built all libraries and integrated it in my custom project, but I don't know what steps should I do to make it work. The only thing that i found with code example\explanation is tech.appear.in/2015/05/25/Getting-started-with-WebRTC-on-iOS , but it is poor and unclear for me, AppRTCDemo source code too. I read about WebRTC for browsers but still can't reproduce it on iOS.
Can anybody explain or provide links to explanation on how to completely build iOS native app using WebRTC API for example p2p ios chat?
Besides the fact that I do not understand code logic provided in demo, I can't understand:
1) What is ICE servers for my iOS app? Should I take care of it? Is it something server side? Should I code and run it myself, or I can use existing Parse background?
2) What is signaling mechanism in iOS app? Is it client side only, or it must be implemented on server side too?
3) And maybe someone can explain step-by-step guide, maybe with some code, how to implement simple iOS p2p chat using WebRTC? For example:
"You have to:
Create ICE/STUN/TURN server on parse core using this =source= and this tutorial =tutorial=.
Create RTCPeerConnection using created ICEServer:
RTCPeerConnectionFactory *pcFactory = [[RTCPeerConnectionFactory alloc] init];
RTCPeerConnection *peerConnection = [pcFactory peerConnectionWithICEServers:kICEServerURL constraints:nil delegate:self];
Create DataChannel using ...
Send signal using ... explained here =link=
Set local and remote descriptions ...
Send Data ... using ...
... " or something similar.
I'm sorry for asking this, but I'm losing my mind trying to figure it out. Thank you!
I am not an expert in webrtc but i will try to explain some of your questions.
1.ICE servers-- NATs and firewalls impose significant problem in setting up IP endpoints. so IETF standards STUN, TURN and ICE were developed to address the NAT traversal problem.
STUN helps connect IP end-points:
discover whether they are behind a NAT/firewall, and if so,
to determine the public IP address and type of the firewall. STUN then uses this information to assist in establishing peer-to-peer IP connectivity.
TURN, which stands for Traversal Using Relay NAT, provides a fallback NAT traversal technique using a media relay server to facilitate media transport between end-points.
ICE is a framework that leverages both STUN and TURN to provide reliable IP set-up and media transport, through a SIP offer/answer model for end-points to exchange multiple candidate IP addresses and ports (such as private addresses and TURN server addresses).
2.Signaling is the process of coordinating communication. This signalling part needs to be implemented by you according to your needs(for ex. if you have sip structure in place then you will have to implement sip signalling). In order for a WebRTC application to set up a 'call', its clients need to exchange information:
Session control messages used to open or close communication.
Error messages.
Media metadata such as codecs and codec settings, bandwidth and media types.
Key data, used to establish secure connections.
Network data, such as a host's IP address and port as seen by the outside world.
Steps
for offerer:
first create the peer connection and pass the ice candidates into it
as parameters.
set event handlers for three events:
onicecandidate-- onicecandidate returns locally generated ICE candidates so you can pass them over other peer(s) i.e. list of ice candidates that are returned by STUN/TURN servers; these ice candidates contains your public ipv4/ipv6 addresses as well as UDP random addresses
onaddstream--onaddstream returns remote stream (microphone and camera of your friend!).
addStream` attaches your local microphone and camera for other peer.
Now create SDP offer by calling setLocalDescription function and set remote SDP by calling setRemoteDescription.
For Answerer:
setRemoteDescription
createAnswer
setLocalDescription
oniceCandidate--On getting locally generated ICE
addiceCandidate--On getting ICE sent by other peer
onaddstream--for remote stream to add
I hope this will make some of your doubts clear.
I came through the process of implementing it few month ago. What I've found was the library was not stable - sometimes it was working sometimes not.
Additionally my iPhone was always becoming hot when I was using it.
I would not suggest using this library and overall WebRTC technology for commercial projects.
This is my implementation, which was working few months ago:
https://github.com/aolszak/WebRTC-iOS
Good luck!

Using Node js in Multiplayer turn based game in ios

Hope u guys are doing great.
I want to make a realtime turn based game in iOS .
I know this can be achieved by using GAME CENTRE in iOS , but i have to play this between browser and iOS app. WEB TEAM is using node js for making this game on web browser , they also suggested me to use node js in iOS game as well.
Have anyone has idea how to use node js for this kind of purpose.
Thanking you all! :)
You can have websocket server written in node js and then just connect to it from your ios app using some websocket library (hope it exists). Then sockets connected from browser and your app can realtime exchange information.
You could use a pub/sub messaging service like Realtime (the company I work for) http://framework.realtime.co/messaging/
Both your node.js server and your ios devices could exchange data through Realtime pub/sub channels, using the node.js and ios SDKs.
The cool part is that since it's a managed service you don't need to worry about the server and networking administration, Realtime will take care of that for you.
I'd like to add some words in favor of #Edgar's answer.
For production, using only WebSocket is not reliable. In environment where WebSocket is not available due to antivirus, enterprise firewall, and so on, a kind of full duplex connection over HTTP should be available utilizing long polling or streaming in terms of reliable real-time connection.
Also such connection might be disconnected for a while e.g. moving away from Wi-Fi zone and then some messages which had to send through that connection may be lost so that a way to recover such messages is required e.g. here is some messages you couldn't receive.
Therefore, you need a reliable framework to write such real-time web application. Here's features which are required to write a real-time web application I think. (It's called Cettia and I'm the author of that project. As it doesn't provide iOS client, it's not right choice for you here. Just focus on features and roadmap to see what features you may be needed and evaluate a framework you will choose based on them.)
On Node.js world, socket.io framework has a great community so I'm sure someone already wrote iOS client for socket.io. Anyway, make sure that the framework you finally chose has features you need to write your real-time webapp.

Is there a public UDP site to test ObjC code?

I'm attempting to learn UDP coding as a neophyte.
I've been doing iOS development for years and want to start learning to do some basic network coding using the UDP protocol.
Is there a practice site to play with where I can't do any harm?
Or... is it possible to merely wire up the Apache server that comes with OS X and work with that?
This is intended to be for an iOS environment so would at least have to work via simulation.
Apache is an HTTP server, HTTP being a protocol built on TCP not UDP. You're probably going to be best off trying to write both a client and server that run in the same application and having them talk to each other via UDP.
FWIW, DNS is based on UDP, so talking to a public DNS server might be a good starting point.

iOS: Thirdparty Frameworks for Socket Communication available

my Task is to send the G-Sensor Data nearly in realtime from an iOS Device to an Application running on a different Device (OSX, iOS, maybe Windows). From all I've read so far, a Socketstream seems to be the best choice for this kind of Task. Do you agree?
My Question is, since I have no experience in Socket programming, are there any third party Frameworks that make socket programming more easier? Maybe that they already created something that will reconnect after the connection was lost and such things like Error Handling? I guess that not everyone invents the wheel again while programming with sockets?
Thank you for any kind of information regarding this topic.
twickl
I would strongly consider CocoaAsyncSocket. It has very much all the callbacks you will need. There are also a version for Tcp and UDP as well.

Resources