Professional Web Applications Themes

carbon and sockets - Mac Programming

Hi, Sorry about the cross posting here, but I should have posted here int the first place. I'm doing my first Mac project that consists of a CFM Carbon shared shared library (it's a plug-in for InDesign). So far, the only problem I'm having is related to opening a socket. I need to send some text via TCP/IP to a server running on the localhost. I tried the bsd sockets, but that apparently doesn't work from carbon. Some doentation leads me to believe that I need to use Open Transport. Can anyone confirm this? I would also like any pointers ...

  1. #1

    Default carbon and sockets

    Hi,

    Sorry about the cross posting here, but I should have posted here
    int the first place.

    I'm doing my first Mac project that consists of a CFM Carbon shared
    shared library (it's a plug-in for InDesign). So far, the only
    problem I'm having is related to opening a socket.

    I need to send some text via TCP/IP to a server running on the
    localhost. I tried the bsd sockets, but that apparently doesn't work
    from carbon. Some doentation leads me to believe that I need
    to use Open Transport. Can anyone confirm this? I would also like
    any pointers and/or examples of opening a tcp connection from a
    CFM Carbon shared library and any info on what to link against for
    this to work (I'm using CW 9).

    This is my first time doing anything on a Mac, including development,
    so please don't be shy with details :)

    Thanks,

    Isaac
    sparrowsmith Guest

  2. #2

    Default Re: carbon and sockets

    In article <net>,
    sparrowsmith <net> wrote:
     

    CFM programs on OS X can call functions in OS X libraries. But they do it
    by extracting function pointers from the library at run time. Here's
    some sample code.


    I find it useful to put my interface routines in a STATIC library, so it
    can have its own access paths, then just include the static library in
    my application.

    typedef int (*ErrnoProc)(void);
    typedef int (*OpenProc)(const char *path, int flags);
    typedef int (*CloseProc)(int);
    typedef int (*FcntlProc)(int fd, int cmd, int arg);
    typedef int (*ReadProc)(int d, void *buf, size_t nbytes);
    typedef int (*WriteProc)(int d, const void *buf, size_t nbytes);


    static ErrnoProc errnop;
    static OpenProc openp;
    static CloseProc closep;
    static FcntlProc fcntlp;
    static ReadProc readp;
    static WriteProc writep;


    OSStatus InitFuncPointers(void){
    OSStatus err = noErr;
    if(noErr == err){
    err = LoadFrameworkBundle(CFSTR("System.framework"), &sysBundle);
    }
    if(noErr == err){
    // see: errno.h in the System framework for the reasoning behind the next line
    errnop = reinterpret_cast_(ErrnoProc)(CFBundleGetFunctionPo interForName(sysBundle, CFSTR("__error")));
    openp = reinterpret_cast_(OpenProc)(CFBundleGetFunctionPoi nterForName(sysBundle, CFSTR("open")));
    closep = reinterpret_cast_(CloseProc)(CFBundleGetFunctionPo interForName(sysBundle, CFSTR("close")));
    fcntlp = reinterpret_cast_(FcntlProc)(CFBundleGetFunctionPo interForName(sysBundle, CFSTR("fcntl")));
    readp = reinterpret_cast_(ReadProc)(CFBundleGetFunctionPoi nterForName(sysBundle, CFSTR("read")));
    }

    // WriteSerialPortCarbonX
    OSStatus WriteSerialPortCarbonX(CSerialPortCarbonX* inP, long *ioLen, const void *inBuffer){
    int val;
    if(NULL == inP){ return paramErr; }
    if(-1 == (val = (*writep)(inP->refNum, inBuffer, *ioLen))){
    if ( (*errnop)() ) return (*errnop)();
    else return val;
    }
    *ioLen = val;
    return noErr;
    }
    David Guest

  3. #3

    Default Re: carbon and sockets

    In article <net>,
    sparrowsmith <net> wrote:
     

    It *does* work from Carbon. But since CFM is for MacOS 9 and X by
    design, and sockets don't really exist on OS 9, you can't use sockets as
    easily in CFM.

    If your plugin is intended to run on OS X only, you will want to look
    at CFBundleGetFunctionPointerForName() (horrible name, I know) to
    manually load the socket functions from "System.framework" (I think
    they're in System, maybe it's some other library).

    Otherwise, OT is probably your best option, or you could look for a
    socket library for OS 9 and use either depending on what you're running
    on.

    Cheers,
    -- Uli
    http://www.zathras.de
    Uli Guest

Similar Threads

  1. Replies: 3
    Last Post: March 7th, 06:21 PM
  2. Replies: 19
    Last Post: December 3rd, 10:32 AM
  3. Carbon and Mach-O?
    By Charles in forum Mac Programming
    Replies: 3
    Last Post: November 19th, 06:35 PM
  4. Using Image Well with Carbon API
    By Frederick Cheung in forum Mac Programming
    Replies: 0
    Last Post: August 10th, 10:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139