Re: Winsock connect to IP
Something like this?:
Code:
SOCKET sock;
unsigned long ip_addr;
struct sockaddr_in client;
ip_addr=inet_addr("192.168.1.10");
memcpy(&client.sin_addr,&ip_addr,sizeof(ip_addr));
client.sin_port=htons(10010);
sock=socket(AF_INET,SOCK_STREAM,0);
connect(sock,(struct sockaddr *)&client,sizeof(client));
Re: Winsock connect to IP
Check out MSDN.
There is some great information here. It is tough to get through at first because there is a lot of jargon. But once you start to learn the terms it makes sense.
Hope this helps!
Re: Winsock connect to IP
Anyways, here is how I do it:
Code:
SOCKET hSocket;
int iResult = 0;
char ipaddress[18] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
int pnum = 0;
//user input here or set values for ipaddress and pnum
hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
sockaddr_in sockAddr1;
sockAddr1.sin_family = AF_INET;
sockAddr1.sin_port = htons(pnum);
sockAddr1.sin_addr.S_un.S_addr = inet_addr((const char*)ipaddress);
iResult=connect( hSocket, (SOCKADDR*) &sockAddr1, (int) sizeof(sockAddr1));
Yes, I use a char array, so what?! It works for me...