There is a code that establishes a connection at a given address to a given port, sends and receives a message from it.
addr.sin_family = AF_INET; addr.sin_port = htons([self.portField.stringValue intValue]); // или любой другой порт... addr.sin_addr.s_addr = inet_addr("127.0.0.1"); In addr.sin_port I transfer the port number from the form. Also from the form I want to pass the address to addr.sin_addr.s_addr.
I tried to do in two ways.
addr.sin_addr.s_addr = inet_addr([self.portField.stringValue cStringUsingEncoding:NSUTF8StringEncoding]); and
addr.sin_addr.s_addr = inet_addr([self.portField.stringValue UTF8String]); But none of these methods works. Tell me how to properly pass a string to a parameter?
Update
Indeed, the problem was with the strings. The following solution helped:
addr.sin_port = htons([ports integerValue]); // или любой другой порт... addr.sin_addr.s_addr = inet_addr([[NSString stringWithFormat:@"%@", adr]UTF8String]);