Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Real-Time Communication with Streams Tutorial for iOS

Learn how you can go down to the TCP layer of the networking stack and build a real-time chat application with this input & output streams tutorial for iOS.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/537-real-time-communication-with-streams-tutorial-for-ios

Hi Luke
Is it is ok to have this kind of approach to use for notifying mobile client app when some updates happens on server.
Our use case involves each and everything whatever happens on server needs to immediate updated to client app.
If we use TCP approach does it will make any impact on apple review process and also is it will drain more battery as its keeps open always stream to receive updates ?

Thanks for this great tutorial.

Can you show us who don’t use the terminal much, how to navigate to the server directory ?

Thanks for the great article! :slight_smile:

I think the tutorial may be missing setting the delegate of the outputStream? I set it after the inputStream delegate. I’m getting an error “Your browser sent a request that this server could not understand” with code that matches the final chat app, is there something extra I have to do to setup the server?

I figured this out myself. Now that I have it running, with my own and the completed code will show an additional set of users printed out in the listener in the terminal window every time a new user name is entered into the user join field. Is this expected?

Project have incorrect layout for tableView, which is tableView.frame = CGRect(x: 0, y: 0 … And message “User has joined” appear behind navigation bar.

Then, go back to ChatRoomViewController.swift and add the same line to viewWillDisappear(_:).
stopChatSession()
Correct is chatRoom.stopChatSession()

How can I modify this to make it use UDP instead of TCP or is it a total make over?

@lxkant Sorry, I’ve not used this in production before so I don’t really have a good answer for you! Feel free to let me know if you find anything out that would be useful to know when building a production system like this!

@roward Sorry I didn’t add more instructions around that, but here’s a link to a nice little article: http://www.macworld.co.uk/feature/mac-software/how-use-terminal-on-mac-3608274/

@surayashivji I don’t think setting the output stream’s delegate is strictly necessary so I didn’t add it, but it shouldn’t hurt either. If you do set it you’ll need to make sure to differentiate between the two streams in the delegate callback method. There shouldn’t be anything extra you need to do to set up the server though! Maybe try going into the Go code and switching the port and then rebuilding the server?

@roward Yeah that’s expected! Just a quirk of telnet I think!

@dony Oh interesting, I wonder if it broke with a new version of Xcode. I’ll pull it down and fix it!

@marse32m I don’t think it would be the easiest thing in the world. I found a gist where someone was sending and receiving UDP packets but it looks they dropped down to plain C for most of it. I haven’t researched enough to know if this is the only way or if there are some better cocoa apis for doing it: https://gist.github.com/chancyWu/8349411

Got through the tutorial. Interesting. Having trouble making it work with a real device connected as opposed to the simulator. I have an iphone6s running 10.3.3. Getting error “Connection has no connected handler-error occurred” when I try to enter the username. Any ideas?

@luke_parham Do you have any feedback on this? Thank you - much appreciated! :]

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]