• 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
Re: Problems with CFSocket and CFStream
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with CFSocket and CFStream


  • Subject: Re: Problems with CFSocket and CFStream
  • From: Martin Bestmann <email@hidden>
  • Date: Wed, 19 Nov 2003 00:00:24 +0100

On 18.11.2003, at 22:37, Jeremy Wyld wrote:


On Nov 18, 2003, at 8:24 AM, Martin Bestmann wrote:

1) CFReadStreamCopyProperty(xReadStream,kCFStreamPropertyShouldCloseNativ eSocket) returns always NULL

kCFStreamPropertyShouldCloseNativeSocket is a "set" property only. Possible oversight on my part?


OK. No problem.

2) CFReadStreamCopyProperty(xReadStream,kCFStreamPropertySocketRemoteHost Name) returns always NULL

This property only returns non-null if the stream had been created with a named host. I believe what you want is to copy out the native socket, get its peer address, create a CFHost from that, and then perform the reverse lookup (if you need the name).


What about CFReadStreamCopyProperty(xReadStream,kCFStreamPropertySocketRemotePortNu mber) this one also returns NULL?

3) After closing the streams with CFReadStreamClose and CFWriteStreamClose and also closing the socket with CFSocketInvalidate and quitting app on next launch of the app (within the next few seconds) we get an error when calling CFSocketCreateWithSocketSignature because of the fact that the system for some reason things that the socket is still occupied.


Make sure to
int yes = 1;
setsockopt(<native socket>, SOL_SOCKET, SO_REUSEADDR, (void*)&yes, sizeof(yes));

See Server.c in /Developer/Examples/Networking/Echo/



I did use the echo sample as base for checking how this do work.
According to the comment in Server.c before the setsockopt it says
// In order to accomadate stopping and starting the process without closing the socket,
// set the addr for resuse on the native socket. This is not required if the port is
// being supplied by the OS opposed to being specified by the user.

Which would mean the socket will not be release when the stream goes away which is not what I want. In any case I did try this and it doesn't work.

After calling
CFStreamCreatePairWithSocket(kCFAllocatorDefault,inSocket,&xReadStream,& xWriteStream);
With inSocket being the PlatformSocketHandle from the callback I do call

// Give up ownership of the native socket.
CFReadStreamSetProperty(xReadStream,kCFStreamPropertyShouldCloseNativeSo cket,kCFBooleanTrue);

Which should do what I want.

Any other ideas. BTW everything works perfect if the client is closing the connection to the server instead of the server closing the connection.

Thanks,

Martin
------------------------------------------------------------------------ -----------------------
Martin Bestmann Netopia Development GmbH
Phone: +49-9134-9942-0 Weingasse 26
Fax: +49-9134-997911 91077 Neunkirchen am Brand
e-mail:email@hidden Germany
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.
References: 
 >Problems with CFSocket and CFStream (From: Martin Bestmann <email@hidden>)
 >Re: Problems with CFSocket and CFStream (From: Jeremy Wyld <email@hidden>)

  • Prev by Date: Re: Problems with CFSocket and CFStream
  • Next by Date: Re: macnetworkprog digest, Vol 3 #585 - 5 msgs
  • Previous by thread: Re: Problems with CFSocket and CFStream
  • Next by thread: Re: macnetworkprog digest, Vol 3 #585 - 5 msgs
  • Index(es):
    • Date
    • Thread