OTConnect() returns kOTOutStateErr
OTConnect() returns kOTOutStateErr
- Subject: OTConnect() returns kOTOutStateErr
- From: Gaurish Kshirsagar <email@hidden>
- Date: Thu, 10 Feb 2005 14:19:19 +0530
Hi,
I'm writing a TCP client to connect from my Mac OS 10.3.7 to an Echo
server running on another machine. I'm using the Open Transport API as
that is the only networking API available with my development
environment. Like most clients, my process flow would be:
Socket() -> Connect() -> Write() -> Read() -> Close().
I'm able to open an endpoint successfully but when I try to connect,
it always fails with the kOTOutStateErr error (Call issued in wrong
state). I paste the snippet of code in context below:
// Returns true if client connected successfully
bool EchoClient::ConnectClient(const char *ipAddr, int portNum,
EndpointRef *retSocket)
{
OSStatus err = noErr;
TCall tCall;
InetAddress remoteIPAddress;
OTClientContextPtr clientContext;
EndpointRef tempSocket;
// Set up the IP in the struct
remoteIPAddress.fPort = portNum;
OTInetStringToHost(ipAddr, &remoteIPAddress.fHost);
// Setup the client context
err = InitOpenTransportInContext(kInitOTForExtensionMask, &clientContext);
if(err != noErr) return false;
// Create the socket
tempSocket = OTOpenEndpointInContext(OTCreateConfiguration(kTCPName),
0, NULL, &err, clientContext);
if(err != noErr) return false;
err = OTSetNonBlocking(tempSocket);
if(err != noErr) return false;
err = OTSetSynchronous(tempSocket);
if(err != noErr) return false;
err = OTUseSyncIdleEvents(tempSocket, true);
if(err != noErr) return false;
// Setup the struct to get the IP
OTMemzero(&tCall, sizeof(TCall));
//tCall.addr.buf = (UInt8 *) &remoteIPAddress;
OTInitInetAddress((InetAddress*)&tCall.addr.buf, portNum,
remoteIPAddress.fHost);
tCall.addr.maxlen = sizeof(remoteIPAddress);
tCall.addr.len = sizeof(remoteIPAddress);
// Attempt the connection -- *** This always fails ***
err = OTConnect(tempSocket, &tCall, NULL);
if(err != noErr) return false;
*retSocket = tempSocket;
return true;
}
Could anyone point out what could be going wrong?
Thanks in advance,
Gaurish
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden