Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 18:25, 2 October 2007.

Socket Connection to an IP Address

From Forum Nokia Wiki

Following is the Open C code to connect to an IP Address given an Access Point name, IP Address and the port. This code uses ioctl to do the job. Similarly, we can do it even without using ioctl

int ConnectToIpAdress(char *apname, char *ipaddr , int port)
{
	ifreq ifr;
	int sockfd;
	struct sockaddr_in destAddr, selfAddr;	
		
	// Name of the interface
	strcpy(ifr.ifr_name, apname);
	
	sockfd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);	
	ioctl(sockfd,SIOCSIFNAME, &ifr);
	ioctl(sockfd, SIOCIFSTART , &ifr);
	
	selfAddr.sin_family = AF_INET;
	selfAddr.sin_addr.s_addr = INADDR_ANY;
	selfAddr.sin_port = htons(port);
	
        //Binding
	bind(sockfd,(struct sockaddr*)&selfAddr, sizeof(selfAddr));
	
	destAddr.sin_family = AF_INET;
	destAddr.sin_addr.s_addr = inet_addr( ipaadr );
	destAddr.sin_port = htons(port);
	connect(sockfd, (struct sockaddr*)&destAddr, sizeof(destAddr));
 
	ioctl(sockfd, SIOCIFSTOP, &ifr);
	close(sockfd);
	return;
}


Links

Reading AP(Access Point) Table

Start new Socket Connection to Access Point

Start new Socket Sub-connection to Access Point

Related Discussions
Thread Thread Starter Forum Replies Last Post
J2ME sockets ravishankarbose Mobile Java Networking & Messaging & Security 2 2004-04-27 07:29
Closing a Socket Connection maniac_2k Symbian Networking & Messaging 4 2004-08-03 14:36
6310i socket connection exception Nokia_Archive Mobile Java Tools & SDKs 4 2002-08-20 21:06
java.net.BindException: The address is not available camroe Mobile Java Networking & Messaging & Security 3 2006-01-20 17:37
Which phones support socket-protocol? andersbergquist Mobile Java Networking & Messaging & Security 5 2005-01-25 08:17
 
Powered by MediaWiki