服务器未检测到winsock中的客户端 [英] server not detecting clients in winsock
本文介绍了服务器未检测到winsock中的客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
netwrok编程的新手我创建了一个服务器端应用程序,因为客户端驻留在微控制器上。我遇到的问题是我无法接收任何传入的连接
Am newbie to netwrok programming i have created a server side application since client side resides a microcontroller. The problem am encountering is that i cannot be able to receive any incoming connections
int main()
{
char ans;
printf("Starting up server........\n");
// our masterSocket(socket that listens for connections)
SOCKET sock;
// for our thread
DWORD thread;
WSADATA wsaData;
sockaddr_in server;
// start winsock
int ret = WSAStartup(0x101, &wsaData); // use highest version of winsock avalible
if (ret != 0)
{
return 0;
}
// fill in winsock struct ...
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
server.sin_port = htons(39950);
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock == INVALID_SOCKET)
{
return 0;
}
// bind our socket to a port(port 123)
if (bind(sock, (sockaddr*)&server, sizeof(server)) != 0)
{
return 0;
}
// listen for a connection
if (listen(sock, 5) != 0)
{
return 0;
}
SOCKET client;
sockaddr_in from;
int fromlen = sizeof(from);
// loop forever
while (true)
{
//printf("check up!!!!!!"); ........ prints this one
// accept connections
client = accept(sock, (struct sockaddr*)&from, &fromlen);
printf("Client connected\r\n"); ...... cannot print this one
// create our recv_cmds thread and parse client socket as a parameter
CreateThread(NULL, 0, receive_cmds, (LPVOID)client, 0, &thread);
}
// shutdown winsock
closesocket(sock);
WSACleanup();
// exit
return 0;
}
推荐答案
你试过写一个客户端 然后连接到您的服务器??
Did you try to write a client and then connect to your server??
Rudolf
这篇关于服务器未检测到winsock中的客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文