From: justin@tasman.cc.utas.edu.au (Justin Ridge)
Subject: ADSP prob: dspOpen gives errState! hints? (Q)
Organization: University of Tasmania, Australia.
Date: Wed, 6 Jan 1993 10:02:34 GMT

Hi once more to comp.sys.mac.programmers.
First, I'd like to thank those who responded to my previous questions
concerning INITs and MacTCP -- thankfully, the problems have been solved.

Now to the point of this posting.  I am trying to write a client
application that will communicate with a server application on another Mac,
via an AppleTalk network, using ADSP in THINK C.  However, I cannot get a
local socket to issue an open request (dspOpen).

To get myself started, I have based my routines on those in IM VI, pp.32-48
to 32-55.  The server uses the connection listener code, and the client
attempts to connect to it using the myADSP routine.
Here is briefly what happens:
* The server application starts up fine.  It registers its socket name
  perfectly, and goes into a loop waiting for open requests to it.
  I have used CheckNET to verify that the socket exists & can be seen etc.
* The client application starts up and will also register ITS name.  Again,
  I have verified this using CheckNET, and by examining the error codes
  returned from the calls.
* The client itself can see the server's socket.  After calling PLookupName()
  the numGotten field is set to one (1), indicating that the server was
  located.
* As far as I can tell, I am then extracting the server's correct address.
* HOWEVER, when I build a control block and open a connection to that server,
  I get an error of -1278: "Bad connection state for this operation."

A relevant section of code is shown below.  Hope I haven't missed any info..
Can anybody suggest what is wrong with my script?  My guess is I am missing
some fields out of the control block, but I cannot tell which ones.
Has anyone else had experience with ADSP that can give some advice or even
simple routines by way of examples?

Thanks in advance for any pointers.  Please send your replies by MAIL
if possible, as I only get to read news like this infrequently.

~~~~~
NBPSetEntity(&server, srvrName, srvrType, srvrZone);
/* form server entity record */
/* srvrName, srvrType, srvrZone = pascal string constants */
/* server is of type NamesTableEntry */
       
(*myMPPPBPtr).NBPinterval = 7;
(*myMPPPBPtr).NBPcount = 3;
(*myMPPPBPtr).NBPentityPtr = &server;
(*myMPPPBPtr).NBPretBuffPtr = myData2ReadPtr;
(*myMPPPBPtr).NBPretBuffSize = myDataSize;
(*myMPPPBPtr).NBPmaxToGet = 1;
(*myMPPPBPtr).NBPverifyFlag = 0;
        
/* get the list of servers matching these criterion */
if ((myErr = PLookupName(myMPPPBPtr, true)) != noErr)
        DoErr(myErr);

/* see if the desired server is in the list - ie. list !empty */
/* myAddrBlk is of type AddrBlock */
if ((myErr = NBPExtract(myData2ReadPtr, (*myMPPPBPtr).NBPnumGotten, 1, myEntity,
                         &myAddrBlk)) != noErr)
         DoErr(myErr);
                
(*myDSPPBPtr).ioCRefNum = drvrRefNum;
(*myDSPPBPtr).csCode = dspOpen;
(*myDSPPBPtr).ccbRefNum = connRefNum;
(*myDSPPBPtr).u.openParams.remoteAddress = myAddrBlk;
(*myDSPPBPtr).u.openParams.filterAddress = myAddrBlk;
(*myDSPPBPtr).u.openParams.ocMode = ocRequest;
(*myDSPPBPtr).u.openParams.ocInterval = 0;
(*myDSPPBPtr).u.openParams.ocMaximum = 0;
        
/* open a connection */
if ((myErr = PBControl(myDSPPBPtr, false)) != noErr)
        DoErr(myErr);
~~~~

PS. I have looked on ftp.apple.com & sumex for examples, or tips in old
copies of Develop & tn's, but wasn't able to come up with anything.

Best regards,
Justin Ridge.

--------------------------------------------------------------------------
Justin Ridge,             |    Phone:  +61 02 202811
Computing Centre          |    Fax  :  +61 02 231772
University of Tasmania    |    Email:  Justin.Ridge@cc.utas.edu.au
--------------------------------------------------------------------------



Newsgroups: comp.sys.mac.programmer