• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
scanning for network printers?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scanning for network printers?


  • Subject: scanning for network printers?
  • From: Alan Dail <email@hidden>
  • Date: Sat, 16 Jul 2005 10:47:26 -0400

The network printer I'm searching for doesn't use Bonjour, but I do know what port it uses. What I'd like to do is be able to scan my local subnet for the device instead of requiring the user to know it's IP address and key it in. I tried opening a connection to the device - the trouble is, if I try this on an address there is no device, it takes about 60 seconds to time out. Clearly this won't work if I need to scan 255 addresses to find the one or ones that actually are the printers I'm looking for. How do I accomplish this and what is the preferred network API for communicating with TCP/IP devices? I've tried cocoa, but found the API to be too limiting (unless I overlooked something). I've also tried OpenTransport as well as the native unix sockets API. Open transport seems to work the best but still has the long timeout for what I'm trying to do - is that what people are using or is there perhaps something I'm overlooking? And is open transport thread safe when using standard Cocoa threads?

Alan

#if qUseCocoaNetwork
NSHost* host = [NSHost hostWithName:[NSString stringWithCString:fDeviceIPAddress.data()]];
[NSStream getStreamsToHost:host port:fDevicePortNumber inputStream:&fInputStream outputStream:&fOutputStream];


    [fOutputStream open];
    if ([fOutputStream hasSpaceAvailable])
        throw Exception(Exception::kUnknownError);
    [fInputStream open];

    [fInputStream retain];
    [fOutputStream retain];

if (IsThreaded())
{
[fInputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[fOutputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
#elif qUseSockets
fSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
int status = connect(fSocket, (struct sockaddr*)&fServerAddress, sizeof(fServerAddress));
if (status < 0)
{
status = errno;
Exception::ThrowIfError(status, fDeviceIPAddress + ": server not responding (connect failed).");
}
#elif qUseOpenTransport
OSStatus status;
fEndPt = ::OTOpenEndpointInContext(::OTCreateConfiguration (kTCPName), 0, NULL, &status, NULL);
if (status == noErr)
{
status = ::OTSetSynchronous(fEndPt);
if (status == noErr)
status = ::OTSetBlocking(fEndPt);
if (status == noErr)
status = ::OTBind(fEndPt, NULL, NULL);


        if (status != noErr)
        {
            ::OTCloseProvider(fEndPt);
            fEndPt = kOTInvalidEndpointRef;
        }
    }
    else
        fEndPt = kOTInvalidEndpointRef;

Exception::ThrowIfError(status, fDeviceIPAddress + ": server not responding (setup failed).");

status = ::OTConnect(fEndPt, &fConnectCall, NULL);
Exception::ThrowIfError(status, fDeviceIPAddress + ": server not responding (OTConnect failed).");
#endif



_______________________________________________ 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
  • Follow-Ups:
    • Re: scanning for network printers?
      • From: Scott Ribe <email@hidden>
  • Prev by Date: Re: CFFTPCreateParsedResourceListing text encoding
  • Next by Date: help scanning for network printers
  • Previous by thread: Re: CFFTPCreateParsedResourceListing text encoding
  • Next by thread: Re: scanning for network printers?
  • Index(es):
    • Date
    • Thread