GithubHelp home page GithubHelp logo

king7532 / flowchat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mpw/flowchat

0.0 2.0 0.0 333 KB

Super simplistic network chat application demonstrating the use of ObjectFlow

Objective-C 100.00%

flowchat's Introduction

FlowChat

Super simplistic network chat application demonstrating the use of ObjectFlow in GUI/networking application.

It is a simple chat client that talks to a local server on port 9001. (You need to start this manually via nc -l 9001 in Terminal window).

Anything typed into the input textfield gets echoed to the chat log and sent to the socket, and any input received from the socket is also echoed to the chat log.

The code of the application is a pipe defined in the AppDelegate's applicationDidFinishLaunching: method, and reflects the diagram fairly directly:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    MPWByteStream *console=[MPWByteStream stream];
    NSURL *chatserver=[NSURL URLWithString:@"socket://localhost:9001"];
    MPWSocketStream *socket=[[MPWSocketStream alloc] initWithURL:chatserver];
    
    self.pipe=[MPWPipe filters:
                 @[ self.messageBox,
                    @"%%@\n",
                    @[
                       @[ @"%me: %@", console] ,
                       @[[MPWByteStream stream], socket,  console ] ],
                  ]
               ];
    
    [self.pipe setTarget:self.messages.textStorage.mutableString];
    [socket open];
}


The pipe specification is an array of filters, with various kinds of objects interpreted specially. An NSControl such as the messageBox is adapted to a stream source that sends its contents via target/action to the stream. The string prefixed with "%" is interpreted as a format string.

An array in a filter array means that the stream is split at this point and the result of the previous filter piped into both substreams. In this case, the message that was typed into the messageBox is sent to both the chatlog (console) and the socket).

The socket output is also sent to the chatlog.

Building

Use carthage update in the project's root directory to fetch and build the MPWFoundation framework. Then build/run via Xcode.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.