diff --git a/libjaylink/discovery_tcp.c b/libjaylink/discovery_tcp.c
index 4079169..c3a6a1e 100644
--- a/libjaylink/discovery_tcp.c
+++ b/libjaylink/discovery_tcp.c
@@ -229,7 +229,11 @@ static struct jaylink_device *probe_device(struct jaylink_context *ctx,
 JAYLINK_PRIV int discovery_tcp_scan(struct jaylink_context *ctx)
 {
 	int ret;
+#ifdef _WIN32
+	SOCKET sock;
+#else
 	int sock;
+#endif
 	int opt_value;
 	fd_set rfds;
 	struct sockaddr_in addr;
@@ -242,7 +246,11 @@ JAYLINK_PRIV int discovery_tcp_scan(struct jaylink_context *ctx)
 
 	sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 
+#ifdef _WIN32
+	if (sock == INVALID_SOCKET) {
+#else
 	if (sock < 0) {
+#endif
 		log_err(ctx, "Failed to create discovery socket");
 		return JAYLINK_ERR;
 	}
diff --git a/libjaylink/libjaylink-internal.h b/libjaylink/libjaylink-internal.h
index d24ea7c..088abbd 100644
--- a/libjaylink/libjaylink-internal.h
+++ b/libjaylink/libjaylink-internal.h
@@ -255,8 +255,13 @@ JAYLINK_PRIV void log_dbgio(const struct jaylink_context *ctx,
 
 /*--- socket.c --------------------------------------------------------------*/
 
+#ifdef _WIN32
+JAYLINK_PRIV int socket_connect(SOCKET sock, const struct sockaddr *address,
+		size_t address_length, size_t timeout);
+#else
 JAYLINK_PRIV int socket_connect(int sock, const struct sockaddr *address,
 		size_t address_length, size_t timeout);
+#endif
 JAYLINK_PRIV bool socket_close(int sock);
 JAYLINK_PRIV bool socket_bind(int sock, const struct sockaddr *address,
 		size_t length);
diff --git a/libjaylink/socket.c b/libjaylink/socket.c
index 6a9fdd7..8882fe3 100644
--- a/libjaylink/socket.c
+++ b/libjaylink/socket.c
@@ -49,8 +49,13 @@
  * @retval JAYLINK_ERR_TIMEOUT A timeout occurred.
  * @retval JAYLINK_ERR Other error conditions.
  */
+#ifdef _WIN32
+JAYLINK_PRIV int socket_connect(SOCKET sock, const struct sockaddr *address,
+		size_t address_length, size_t timeout)
+#else
 JAYLINK_PRIV int socket_connect(int sock, const struct sockaddr *address,
 		size_t address_length, size_t timeout)
+#endif
 {
 	int ret;
 	fd_set fds;
diff --git a/libjaylink/transport_tcp.c b/libjaylink/transport_tcp.c
index dc38d8f..ebdb522 100644
--- a/libjaylink/transport_tcp.c
+++ b/libjaylink/transport_tcp.c
@@ -266,7 +266,11 @@ JAYLINK_PRIV int transport_tcp_open(struct jaylink_device_handle *devh)
 	for (struct addrinfo *rp = info; rp != NULL; rp = rp->ai_next) {
 		sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
 
+#ifdef _WIN32
+		if (sock == SOCKET_ERROR)
+#else
 		if (sock < 0)
+#endif
 			continue;
 
 		ret = socket_connect(sock, info->ai_addr, info->ai_addrlen,
@@ -286,7 +290,11 @@ JAYLINK_PRIV int transport_tcp_open(struct jaylink_device_handle *devh)
 
 	freeaddrinfo(info);
 
+#ifdef _WIN32
+	if (sock == SOCKET_ERROR) {
+#else
 	if (sock < 0) {
+#endif
 		log_err(ctx, "Failed to open device");
 		cleanup_handle(devh);
 		return JAYLINK_ERR;
