For any networking code, make sure you’re using htonl & htons when building a socket address structure. If you look at the structure you’re passing to connect(), the IP address & port should appear reversed. Dealing with these byte ordering issues can be very confusing. Always be aware of what byte order is expected for any data used externally or passed to system calls.