• 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: CFSocket
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFSocket


  • Subject: Re: CFSocket
  • From: "sunil prajapati" <email@hidden>
  • Date: Thu, 22 Nov 2007 12:33:34 +0530

Thanks for reply.

When I run client/server,client get connected with server but when I
send some data to client it does not receive by the client. I mean to
say  callback function "receiveData" is not called by CFSocket. This
problem is occur when I create the CFSocket on a thread as I have
given the source code below.  But when I create the CFSocket in a
normal function it works properly.

My Sourcecode for CFSocket is as follows:

int main()
{
pthread_create( &tcpThread ,NULL ,TCPCFSocketCreate,NULL );
}

void* TCPCFSocketCreate(void* val)
{

	char tcperrorMsg[MAX_SIZE ];
	struct hostent *phostent;
	socklen_t length;
	CFSocketRef  CFSocketchild ;
	tcpPortNo =1024;
	unsigned int ip = server.sin_addr.s_addr;
	char *p=(char *)&ip;
	bzero(&ipstr,15);
	sprintf((char *)ipstr,"%d.%d.%d.%d",(unsigned char)p[0],(unsigned
char)p[1],(unsigned char)p[2],(unsigned char)p[3]);

	struct sockaddr_in tcpip_sa;
	iConnectTCPSocket=socket(AF_INET,SOCK_STREAM,0);
	tcpip_sa.sin_len = sizeof(struct sockaddr_in);
	tcpip_sa.sin_family = AF_INET;
	tcpip_sa.sin_addr.s_addr = htonl(INADDR_ANY);
	tcpip_sa.sin_port = htons(tcpPortNo);
	phostent = gethostbyname(ipstr);
	bcopy((char *)phostent->h_addr,
			  (char *)&tcpip_sa.sin_addr.s_addr,
			  phostent->h_length);

	tcpip_sa.sin_len = sizeof(struct sockaddr_in);
	length = sizeof(struct sockaddr_in);
	memset (&(tcpip_sa.sin_zero), '\0', 8);
	if (connect(iConnectTCPSocket,(struct sockaddr
*)&tcpip_sa,sizeof(tcpip_sa)) < 0)
		{
			printf("Error: Connecting to Server.\n");

		}


	CFSocketchild=CFSocketCreateWithNative(NULL,(CFSocketNativeHandle)iConnectTCPSocket,kCFSocketDataCallBack,receiveData,NULL);

	int isocketWRet = write(iConnectTCPSocket, &clientinfo, sizeof(clientinfo));
	if(isocketWRet==0)
	{
		sprintf(tcperrorMsg ,strerror(errno));

	}

	CFRunLoopSourceRef childSource = CFSocketCreateRunLoopSource(NULL,
CFSocketchild, 0);
	CFRunLoopRef loop = CFRunLoopGetCurrent();

	CFRunLoopAddSource(loop, childSource, kCFRunLoopDefaultMode);

	//CFRelease(childSource);



}

void receiveData(CFSocketRef child, CFSocketCallBackType type,
CFDataRef address, const void *data, void *info)
{
    printf("Data from server\n");
}


Thanks,
Sunil.



On Nov 21, 2007 11:19 PM, Joseph Kelly <email@hidden> wrote:
> Did you create a run loop source for the socket using CFSocketCreateRunLoopSource() and add it to the thread's run loop using CFRunLoopAddSource()?
>
> That's all  I can think of w/o looking at your source.
>
> Joe K.
>
>
> On Wednesday, November 21, 2007, at 10:11AM, "sunil prajapati" <email@hidden> wrote:
> >Hi Guys,
> >
> >I have developed one client/server application in Carbon.
> >I am getting the problem when I create the CFSocket on a thread then
> >the  callback function does not work. But when I create it in a normal
> >function then it works properly.
> >What is the reason CFSocket does not work on my created thread?
> >
> >Thanks,
> >Sunil.
>
>
 _______________________________________________
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: CFSocket
      • From: Ben Artin <email@hidden>
References: 
 >CFSocket (From: "sunil prajapati" <email@hidden>)
 >Re: CFSocket (From: Joseph Kelly <email@hidden>)

  • Prev by Date: Re: CFSocket
  • Next by Date: Re: CFSocket
  • Previous by thread: Re: CFSocket
  • Next by thread: Re: CFSocket
  • Index(es):
    • Date
    • Thread