Path: utzoo!utgpu!watmath!iuvax!rutgers!bellcore!spectral!sjs From: sjs@spectral.ctt.bellcore.com (Stan Switzer) Newsgroups: comp.windows.news Subject: Re: sockets Keywords: sockets Message-ID: <18065@bellcore.bellcore.com> Date: 26 Oct 89 18:02:45 GMT References: <9126@batcomputer.tn.cornell.edu> <9150@batcomputer.tn.cornell.edu> Sender: news@bellcore.bellcore.com Reply-To: sjs@sjs@bellcore.com (Stan Switzer) Distribution: comp Organization: Bellcore Lines: 74 In article <9150@batcomputer.tn.cornell.edu> prove@batcomputer.tn.cornell.edu (Roger Ove) writes: > In response to my own query: > > > Could someone please post an example using a socket connection > > between 2 NeWS processes? I have a pixrect image stored in a string > > and want to display it with readcanvas imagecanvas, without going to > > disk. An example receiving the data via separate socket from the C > > client would also be useful (to avoid NeWS string length restrictions). > > There is no difficulty in passing data between the C Client and > NeWS process via a secondary socket connection, the most obvious > thing works (I'll mail the example if anyone is interested). > Help with the first question would still be appreciated. > > thanks, > Roger Ove ove@ncsa.uiuc.edu OK, here's an example. The trick is that file names of the form (%socket[cl]nnn[.nnnnn]) are special. "c" means connect. "l" means listen. The first number is the socket number. The second number, if present, is the internet address (in decimal!). If the address is left off, localhost is the default. I have the opposite problem. I want to send a rasterfile via writecanvas to a C client from NeWS. I basically know how to do it, but I haven't done much socket hacking (in C) so an example would be greatly appreciated. I don't think you can do UDP sockets though, which is too bad since I am sorely tempted to write a SunRPC handler in NeWS so that I can write a yellow-pages client. Example follows. I haven't the foggiest idea why normal EOF detection on "currentfile" doesn't work. Stan Switzer sjs@bellcore.com ---------- #!/usr/NeWS/bin/psh % simple socket I/O example /buff1 100 string def /buff2 100 string def /receiver { /insocket (%socketl2345) (r) file acceptconnection def { % loop... insocket buff1 readline not { exit } if % read a line from socket == % print a line } loop (End of Input) == } fork def pause pause % give the process a chance to get launched { % sender: /outsocket (%socketc2345) (w) file def { % loop... currentfile buff2 readline not { exit } if % read a line from stdin dup (EOF) eq { exit } if outsocket exch writestring outsocket (\n) writestring outsocket flushfile } loop /outsocket null def % close output socket receiver waitprocess } exec line 1 another line line 3 last line EOF