home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1997 November / Macworld (1997-11).dmg / Shareware World / Comms & Internet / StreamWatcher 1.0 / Developer Extras.sit / Developer Extras / StreamWatcher Example / StreamWatcherExample.c next >
MacBinary  |  1997-08-11  |  2.6 KB  |  [TEXT/CWIE]

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: MacBinary (archive/macBinary).

You can browse this item here: StreamWatcherExample.c

ConfidenceProgramDetectionMatch TypeSupport
66% dexvert Compact Compressed (Unix) (archive/compact) ext Supported
10% dexvert MacBinary (archive/macBinary) fallback Supported
1% dexvert Text File (text/txt) fallback Supported
100% file MacBinary II, inited, Mon Aug 11 17:07:39 1997, modified Mon Aug 11 17:07:39 1997, creator 'CWIE', type ASCII, 2008 bytes "StreamWatcherExample.c" , at 0x858 428 bytes resource default (weak)
99% file data default
74% TrID Macintosh plain text (MacBinary) default
25% TrID MacBinary 2 default (weak)
100% siegfried fmt/1762 MacBinary (II) default
100% lsar MacBinary default


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[CWIE]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 16 53 74 72 65 61 6d | 57 61 74 63 68 65 72 45 |..Stream|WatcherE|
|00000010| 78 61 6d 70 6c 65 2e 63 | 00 00 00 00 00 00 00 00 |xample.c|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 54 45 58 54 43 57 49 | 45 01 00 00 00 00 00 00 |.TEXTCWI|E.......|
|00000050| 00 00 00 00 00 07 d8 00 | 00 01 ac b0 15 2f 9b b0 |........|...../..|
|00000060| 15 2f 9b 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |./......|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 67 ed 00 00 |........|....g...|
|00000080| 23 69 6e 63 6c 75 64 65 | 20 3c 4f 70 65 6e 54 72 |#include| <OpenTr|
|00000090| 61 6e 73 70 6f 72 74 2e | 68 3e 0d 23 69 6e 63 6c |ansport.|h>.#incl|
|000000a0| 75 64 65 20 3c 4f 70 65 | 6e 54 70 74 49 6e 74 65 |ude <Ope|nTptInte|
|000000b0| 72 6e 65 74 2e 68 3e 0d | 23 69 6e 63 6c 75 64 65 |rnet.h>.|#include|
|000000c0| 20 3c 45 76 65 6e 74 73 | 2e 68 3e 0d 23 69 6e 63 | <Events|.h>.#inc|
|000000d0| 6c 75 64 65 20 3c 73 74 | 64 69 6f 2e 68 3e 0d 23 |lude <st|dio.h>.#|
|000000e0| 69 6e 63 6c 75 64 65 20 | 3c 73 74 72 69 6e 67 2e |include |<string.|
|000000f0| 68 3e 0d 0d 73 74 61 74 | 69 63 20 55 49 6e 74 33 |h>..stat|ic UInt3|
|00000100| 32 20 67 4c 61 73 74 54 | 69 63 6b 73 20 3d 20 30 |2 gLastT|icks = 0|
|00000110| 3b 0d 0d 73 74 61 74 69 | 63 20 70 61 73 63 61 6c |;..stati|c pascal|
|00000120| 20 76 6f 69 64 20 4d 79 | 4e 6f 74 69 66 69 65 72 | void My|Notifier|
|00000130| 28 76 6f 69 64 2a 20 63 | 6f 6e 74 65 78 74 50 74 |(void* c|ontextPt|
|00000140| 72 2c 20 4f 54 45 76 65 | 6e 74 43 6f 64 65 20 63 |r, OTEve|ntCode c|
|00000150| 6f 64 65 2c 20 0d 09 09 | 09 09 09 09 09 09 09 20 |ode, ...|....... |
|00000160| 20 20 4f 54 52 65 73 75 | 6c 74 20 72 65 73 75 6c | OTResu|lt resul|
|00000170| 74 2c 20 76 6f 69 64 2a | 20 63 6f 6f 6b 69 65 29 |t, void*| cookie)|
|00000180| 0d 7b 0d 09 23 70 72 61 | 67 6d 61 20 75 6e 75 73 |.{..#pra|gma unus|
|00000190| 65 64 28 63 6f 6e 74 65 | 78 74 50 74 72 29 0d 09 |ed(conte|xtPtr)..|
|000001a0| 23 70 72 61 67 6d 61 20 | 75 6e 75 73 65 64 28 72 |#pragma |unused(r|
|000001b0| 65 73 75 6c 74 29 0d 09 | 23 70 72 61 67 6d 61 20 |esult)..|#pragma |
|000001c0| 75 6e 75 73 65 64 28 63 | 6f 6f 6b 69 65 29 0d 09 |unused(c|ookie)..|
|000001d0| 0d 09 73 77 69 74 63 68 | 20 28 63 6f 64 65 29 20 |..switch| (code) |
|000001e0| 7b 0d 09 09 63 61 73 65 | 20 6b 4f 54 53 79 6e 63 |{...case| kOTSync|
|000001f0| 49 64 6c 65 45 76 65 6e | 74 3a 0d 09 09 09 69 66 |IdleEven|t:....if|
|00000200| 20 28 20 54 69 63 6b 43 | 6f 75 6e 74 28 29 20 3e | ( TickC|ount() >|
|00000210| 20 67 4c 61 73 74 54 69 | 63 6b 73 20 2b 20 31 30 | gLastTi|cks + 10|
|00000220| 29 20 7b 0d 09 09 09 09 | 70 72 69 6e 74 66 28 22 |) {.....|printf("|
|00000230| 2e 22 29 3b 0d 09 09 09 | 09 66 66 6c 75 73 68 28 |.");....|.fflush(|
|00000240| 73 74 64 6f 75 74 29 3b | 0d 09 09 09 09 67 4c 61 |stdout);|.....gLa|
|00000250| 73 74 54 69 63 6b 73 20 | 3d 20 54 69 63 6b 43 6f |stTicks |= TickCo|
|00000260| 75 6e 74 28 29 3b 0d 09 | 09 09 7d 0d 09 09 09 62 |unt();..|..}....b|
|00000270| 72 65 61 6b 3b 0d 09 09 | 64 65 66 61 75 6c 74 3a |reak;...|default:|
|00000280| 0d 09 09 09 2f 2f 20 64 | 6f 20 6e 6f 74 68 69 6e |....// d|o nothin|
|00000290| 67 0d 09 09 09 62 72 65 | 61 6b 3b 0d 09 7d 0d 7d |g....bre|ak;..}.}|
|000002a0| 0d 0d 73 74 61 74 69 63 | 20 63 68 61 72 20 2a 67 |..static| char *g|
|000002b0| 48 54 54 50 53 65 72 76 | 65 72 20 3d 20 22 77 77 |HTTPServ|er = "ww|
|000002c0| 77 2e 73 74 61 69 72 77 | 61 79 73 2e 63 6f 6d 3a |w.stairw|ays.com:|
|000002d0| 38 30 22 3b 0d 73 74 61 | 74 69 63 20 63 68 61 72 |80";.sta|tic char|
|000002e0| 20 2a 67 47 65 74 48 54 | 54 50 43 6f 6d 6d 61 6e | *gGetHT|TPComman|
|000002f0| 64 20 3d 20 22 47 45 54 | 20 2f 20 48 54 54 50 2f |d = "GET| / HTTP/|
|00000300| 31 2e 30 5c 31 35 5c 31 | 32 5c 31 35 5c 31 32 22 |1.0\15\1|2\15\12"|
|00000310| 3b 0d 0d 76 6f 69 64 20 | 6d 61 69 6e 28 76 6f 69 |;..void |main(voi|
|00000320| 64 29 0d 7b 0d 09 45 6e | 64 70 6f 69 6e 74 52 65 |d).{..En|dpointRe|
|00000330| 66 20 65 70 3b 0d 09 4f | 53 53 74 61 74 75 73 20 |f ep;..O|SStatus |
|00000340| 65 72 72 3b 0d 09 54 43 | 61 6c 6c 20 63 6f 6e 6e |err;..TC|all conn|
|00000350| 65 63 74 43 61 6c 6c 3b | 0d 09 44 4e 53 41 64 64 |ectCall;|..DNSAdd|
|00000360| 72 65 73 73 20 63 6f 6e | 6e 65 63 74 41 64 64 72 |ress con|nectAddr|
|00000370| 3b 0d 09 4f 54 52 65 73 | 75 6c 74 20 62 79 74 65 |;..OTRes|ult byte|
|00000380| 73 53 65 6e 74 3b 0d 09 | 4f 54 52 65 73 75 6c 74 |sSent;..|OTResult|
|00000390| 20 62 79 74 65 73 52 65 | 63 65 69 76 65 64 3b 0d | bytesRe|ceived;.|
|000003a0| 09 63 68 61 72 20 63 68 | 3b 0d 09 4f 54 46 6c 61 |.char ch|;..OTFla|
|000003b0| 67 73 20 6a 75 6e 6b 46 | 6c 61 67 73 3b 0d 09 0d |gs junkF|lags;...|
|000003c0| 09 70 72 69 6e 74 66 28 | 22 48 65 6c 6c 6f 20 43 |.printf(|"Hello C|
|000003d0| 72 75 65 6c 20 57 6f 72 | 6c 64 21 5c 6e 22 29 3b |ruel Wor|ld!\n");|
|000003e0| 0d 09 0d 09 65 72 72 20 | 3d 20 49 6e 69 74 4f 70 |....err |= InitOp|
|000003f0| 65 6e 54 72 61 6e 73 70 | 6f 72 74 28 29 3b 0d 09 |enTransp|ort();..|
|00000400| 69 66 20 28 65 72 72 20 | 3d 3d 20 6e 6f 45 72 72 |if (err |== noErr|
|00000410| 29 20 7b 0d 09 09 65 70 | 20 3d 20 4f 54 4f 70 65 |) {...ep| = OTOpe|
|00000420| 6e 45 6e 64 70 6f 69 6e | 74 28 4f 54 43 72 65 61 |nEndpoin|t(OTCrea|
|00000430| 74 65 43 6f 6e 66 69 67 | 75 72 61 74 69 6f 6e 28 |teConfig|uration(|
|00000440| 22 53 74 72 65 61 6d 57 | 61 74 63 68 65 72 2c 74 |"StreamW|atcher,t|
|00000450| 63 70 22 29 2c 20 30 2c | 20 6e 69 6c 2c 20 26 65 |cp"), 0,| nil, &e|
|00000460| 72 72 29 3b 0d 09 09 69 | 66 20 28 65 72 72 20 3d |rr);...i|f (err =|
|00000470| 3d 20 6e 6f 45 72 72 29 | 20 7b 0d 09 09 09 28 76 |= noErr)| {....(v|
|00000480| 6f 69 64 29 20 4f 54 53 | 65 74 53 79 6e 63 68 72 |oid) OTS|etSynchr|
|00000490| 6f 6e 6f 75 73 28 65 70 | 29 3b 0d 09 09 09 28 76 |onous(ep|);....(v|
|000004a0| 6f 69 64 29 20 4f 54 53 | 65 74 42 6c 6f 63 6b 69 |oid) OTS|etBlocki|
|000004b0| 6e 67 28 65 70 29 3b 0d | 09 09 09 28 76 6f 69 64 |ng(ep);.|...(void|
|000004c0| 29 20 4f 54 55 73 65 53 | 79 6e 63 49 64 6c 65 45 |) OTUseS|yncIdleE|
|000004d0| 76 65 6e 74 73 28 65 70 | 2c 20 74 72 75 65 29 3b |vents(ep|, true);|
|000004e0| 0d 09 09 09 28 76 6f 69 | 64 29 20 4f 54 49 6e 73 |....(voi|d) OTIns|
|000004f0| 74 61 6c 6c 4e 6f 74 69 | 66 69 65 72 28 65 70 2c |tallNoti|fier(ep,|
|00000500| 20 4d 79 4e 6f 74 69 66 | 69 65 72 2c 20 30 29 3b | MyNotif|ier, 0);|
|00000510| 0d 09 09 09 28 76 6f 69 | 64 29 20 4f 54 42 69 6e |....(voi|d) OTBin|
|00000520| 64 28 65 70 2c 20 6e 69 | 6c 2c 20 6e 69 6c 29 3b |d(ep, ni|l, nil);|
|00000530| 0d 09 09 09 0d 09 09 09 | 4f 54 4d 65 6d 7a 65 72 |........|OTMemzer|
|00000540| 6f 28 26 63 6f 6e 6e 65 | 63 74 43 61 6c 6c 2c 20 |o(&conne|ctCall, |
|00000550| 73 69 7a 65 6f 66 28 63 | 6f 6e 6e 65 63 74 43 61 |sizeof(c|onnectCa|
|00000560| 6c 6c 29 29 3b 0d 09 09 | 09 63 6f 6e 6e 65 63 74 |ll));...|.connect|
|00000570| 43 61 6c 6c 2e 61 64 64 | 72 2e 62 75 66 20 3d 20 |Call.add|r.buf = |
|00000580| 28 55 49 6e 74 38 20 2a | 29 20 26 63 6f 6e 6e 65 |(UInt8 *|) &conne|
|00000590| 63 74 41 64 64 72 3b 0d | 09 09 09 63 6f 6e 6e 65 |ctAddr;.|...conne|
|000005a0| 63 74 43 61 6c 6c 2e 61 | 64 64 72 2e 6c 65 6e 20 |ctCall.a|ddr.len |
|000005b0| 3d 20 4f 54 49 6e 69 74 | 44 4e 53 41 64 64 72 65 |= OTInit|DNSAddre|
|000005c0| 73 73 28 26 63 6f 6e 6e | 65 63 74 41 64 64 72 2c |ss(&conn|ectAddr,|
|000005d0| 20 67 48 54 54 50 53 65 | 72 76 65 72 29 3b 0d 09 | gHTTPSe|rver);..|
|000005e0| 09 09 0d 09 09 09 65 72 | 72 20 3d 20 4f 54 43 6f |......er|r = OTCo|
|000005f0| 6e 6e 65 63 74 28 65 70 | 2c 20 26 63 6f 6e 6e 65 |nnect(ep|, &conne|
|00000600| 63 74 43 61 6c 6c 2c 20 | 6e 69 6c 29 3b 0d 09 09 |ctCall, |nil);...|
|00000610| 09 0d 09 09 09 69 66 20 | 28 65 72 72 20 3d 3d 20 |.....if |(err == |
|00000620| 6e 6f 45 72 72 29 20 7b | 0d 09 09 09 09 62 79 74 |noErr) {|.....byt|
|00000630| 65 73 53 65 6e 74 20 3d | 20 4f 54 53 6e 64 28 65 |esSent =| OTSnd(e|
|00000640| 70 2c 20 67 47 65 74 48 | 54 54 50 43 6f 6d 6d 61 |p, gGetH|TTPComma|
|00000650| 6e 64 2c 20 73 74 72 6c | 65 6e 28 67 47 65 74 48 |nd, strl|en(gGetH|
|00000660| 54 54 50 43 6f 6d 6d 61 | 6e 64 29 2c 20 30 29 3b |TTPComma|nd), 0);|
|00000670| 0d 09 09 09 09 69 66 20 | 28 20 62 79 74 65 73 53 |.....if |( bytesS|
|00000680| 65 6e 74 20 3c 20 30 20 | 29 20 7b 0d 09 09 09 09 |ent < 0 |) {.....|
|00000690| 09 65 72 72 20 3d 20 62 | 79 74 65 73 53 65 6e 74 |.err = b|ytesSent|
|000006a0| 3b 0d 09 09 09 09 7d 0d | 09 09 09 7d 0d 09 09 09 |;.....}.|...}....|
|000006b0| 69 66 20 28 65 72 72 20 | 3d 3d 20 6e 6f 45 72 72 |if (err |== noErr|
|000006c0| 29 20 7b 0d 09 09 09 09 | 64 6f 20 7b 0d 09 09 09 |) {.....|do {....|
|000006d0| 09 09 62 79 74 65 73 52 | 65 63 65 69 76 65 64 20 |..bytesR|eceived |
|000006e0| 3d 20 4f 54 52 63 76 28 | 65 70 2c 20 26 63 68 2c |= OTRcv(|ep, &ch,|
|000006f0| 20 31 2c 20 26 6a 75 6e | 6b 46 6c 61 67 73 29 3b | 1, &jun|kFlags);|
|00000700| 0d 09 09 09 09 09 69 66 | 20 28 62 79 74 65 73 52 |......if| (bytesR|
|00000710| 65 63 65 69 76 65 64 20 | 3c 20 30 29 20 7b 0d 09 |eceived |< 0) {..|
|00000720| 09 09 09 09 09 65 72 72 | 20 3d 20 62 79 74 65 73 |.....err| = bytes|
|00000730| 52 65 63 65 69 76 65 64 | 3b 0d 09 09 09 09 09 7d |Received|;......}|
|00000740| 20 65 6c 73 65 20 7b 0d | 09 09 09 09 09 09 70 72 | else {.|......pr|
|00000750| 69 6e 74 66 28 22 25 63 | 22 2c 20 63 68 29 3b 0d |intf("%c|", ch);.|
|00000760| 09 09 09 09 09 7d 0d 09 | 09 09 09 7d 20 77 68 69 |.....}..|...} whi|
|00000770| 6c 65 20 28 65 72 72 20 | 3d 3d 20 6e 6f 45 72 72 |le (err |== noErr|
|00000780| 29 3b 0d 09 09 09 7d 0d | 09 09 09 0d 09 09 09 4f |);....}.|.......O|
|00000790| 54 43 6c 6f 73 65 50 72 | 6f 76 69 64 65 72 28 65 |TClosePr|ovider(e|
|000007a0| 70 29 3b 0d 09 09 7d 0d | 09 09 43 6c 6f 73 65 4f |p);...}.|..CloseO|
|000007b0| 70 65 6e 54 72 61 6e 73 | 70 6f 72 74 28 29 3b 0d |penTrans|port();.|
|000007c0| 09 7d 0d 09 0d 09 69 66 | 20 28 65 72 72 20 3d 3d |.}....if| (err ==|
|000007d0| 20 6e 6f 45 72 72 29 20 | 7b 0d 09 09 70 72 69 6e | noErr) |{...prin|
|000007e0| 74 66 28 22 53 75 63 63 | 65 73 73 21 5c 6e 22 29 |tf("Succ|ess!\n")|
|000007f0| 3b 0d 09 7d 20 65 6c 73 | 65 20 7b 0d 09 09 70 72 |;..} els|e {...pr|
|00000800| 69 6e 74 66 28 22 46 61 | 69 6c 65 64 20 77 69 74 |intf("Fa|iled wit|
|00000810| 68 20 65 72 72 6f 72 20 | 25 64 2e 5c 6e 22 2c 20 |h error |%d.\n", |
|00000820| 65 72 72 29 3b 0d 09 7d | 0d 09 70 72 69 6e 74 66 |err);..}|..printf|
|00000830| 28 22 44 6f 6e 65 2e 20 | 20 50 72 65 73 73 20 63 |("Done. | Press c|
|00000840| 6f 6d 6d 61 6e 64 2d 51 | 20 74 6f 20 51 75 69 74 |ommand-Q| to Quit|
|00000850| 2e 5c 6e 22 29 3b 0d 7d | 00 00 00 00 00 00 00 00 |.\n");.}|........|
|00000860| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000870| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000880| 00 00 01 00 00 00 01 5a | 00 00 00 5a 00 00 00 52 |.......Z|...Z...R|
|00000890| 65 72 00 00 b9 70 72 6f | 74 54 79 70 65 00 07 96 |er...pro|tType...|
|000008a0| 68 61 6e 64 6c 65 72 00 | 06 b9 73 6f 63 6b 65 74 |handler.|..socket|
|000008b0| 16 53 74 72 65 61 6d 57 | 61 74 63 68 65 72 45 78 |.StreamW|atcherEx|
|000008c0| 61 6d 70 6c 65 2e 63 72 | 02 00 00 00 54 45 58 54 |ample.cr|....TEXT|
|000008d0| 00 00 54 45 58 54 43 57 | 49 45 01 00 ff ff ff ff |..TEXTCW|IE......|
|000008e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000008f0| 44 19 af db 9f b8 00 00 | 07 d8 00 00 01 ac 74 42 |D.......|......tB|
|00000900| 75 66 66 50 74 72 00 03 | 2c 72 65 74 42 75 66 66 |uffPtr..|,retBuff|
|00000910| 53 69 7a 65 00 00 a9 6d | 61 78 54 6f 47 65 74 00 |Size...m|axToGet.|
|00000920| 01 89 6e 75 6d 47 6f 74 | 74 65 6e 00 03 51 63 6f |..numGot|ten..Qco|
|00000930| 6e 66 69 72 6d 41 64 64 | 72 00 01 8b 6e 65 77 53 |nfirmAdd|r...newS|
|00000940| 6f 63 6b 65 74 00 07 6b | 66 69 6c 6c 65 72 34 00 |ocket..k|filler4.|
|00000950| 03 ae 6e 65 77 53 65 6c | 66 46 6c 61 67 00 03 1c |..newSel|fFlag...|
|00000960| 6f 6c 64 53 65 6c 66 46 | 6c 61 67 00 00 0f 6e 4b |oldSelfF|lag...nK|
|00000970| 69 6c 6c 51 45 6c 00 07 | 44 76 65 72 73 69 6f 6e |illQEl..|Dversion|
|00000980| 00 00 00 48 00 09 47 65 | 6e 65 76 61 00 00 00 00 |...H..Ge|neva....|
|00000990| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000009a0| 00 00 00 00 00 00 00 02 | 00 02 00 2e 00 0a 02 f5 |........|........|
|000009b0| 02 8a 00 2e 00 0a 02 f5 | 02 8a b0 14 f0 72 00 00 |........|.....r..|
|000009c0| 03 aa 00 00 03 d4 00 00 | 01 c9 01 00 00 00 00 02 |........|........|
|000009d0| 00 00 00 00 00 04 00 01 | 00 01 00 00 01 00 00 00 |........|........|
|000009e0| 01 5a 00 00 00 5a 00 00 | 00 52 02 c6 5c 94 1c a6 |.Z...Z..|.R..\...|
|000009f0| 00 00 00 1c 00 52 00 01 | 4d 50 53 52 00 01 00 12 |.....R..|MPSR....|
|00000a00| 4d 57 42 42 00 00 00 2a | 03 ed ff ff 00 00 00 00 |MWBB...*|........|
|00000a10| 00 00 00 00 03 ef ff ff | 00 00 00 4c 00 00 00 00 |........|...L....|
|00000a20| 03 f0 ff ff 00 00 00 52 | 00 00 00 00 00 00 00 00 |.......R|........|
|00000a30| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a40| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a50| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a60| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000a70| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
+--------+-------------------------+-------------------------+--------+--------+