UDP SOCKET socket communication problems!

The UDP server creates four socket, port binding for 6000-6003 after the client to the server, which sends a port request. The server received later save the SOCKADDR_IN address of the client. Then the client to the server 4 ports to send data, the server can receive success, the client can only receive the first request to send data to the port, where the reason?

Started by Berger at November 23, 2016 - 1:12 PM

Their top!!!

Posted by Berger at December 08, 2016 - 1:57 PM

What is this problem?
Cannot read the pass by.

Posted by Tommy at December 19, 2016 - 2:37 PM

Send the code to have a look?

Posted by Christian at December 29, 2016 - 3:00 PM

You add cycle "listening".?

Posted by Gale at January 01, 2017 - 3:39 PM

Plus, the local test normal, put the server this problem.

Posted by Berger at January 04, 2017 - 3:08 PM

My code is C++, the implementation is kept on the server, the client of any monitoring of SOCKADDR_IN after the data to the server, the client on each port, the server received immediately after recovery. In the local test normal, put the server problems.

Posted by Berger at January 04, 2017 - 3:32 PM

SOCKET sock[4];
SOCKADDR_IN userAddr;
SOCKADDR_IN si;
si.sin_family = AF_INET;
si.sin_addr.S_un.S_addr = INADDR_ANY;

//Create a thread
for(int i=0; i <THREAD_NUM; ++i)
{
si.sin_port = htons(6000 + i);
sock[i] = socket(AF_INET,SOCK_DGRAM,0);
if(bind(sock[i], (sockaddr*)&g_si, sizeof(g_si)) == SOCKET_ERROR)
{
MessageBox(_T("Bind failed!"));
return;
}
HANDLE hThreadHandle = CreateThread(NULL, 0, ServerThread, (LPVOID)i, 0, 0);
if (hThreadHandle == NULL)
{
MessageBox(_T("Create a thread failure!"));
return;
}
CloseHandle(hThreadHandle);

}

//Monitor
DWORD WINAPI CUdpGameServerDlg::ServerThread (LPVOID lpParam)
{
DWORD dwTrans;
DWORD nFlags = 0;
int nLen = sizeof(SOCKADDR);

SOCKADDR_IN addrClient;
char tem[BUFFER_SIZE];

WSABUF buf;
buf.buf = tem;
buf.len = BUFFER_SIZE;
int ThreadID = (int)lpParam;

while(TRUE)
{
WSARecvFrom(sock[ThreadID], &buf, 1, &dwTrans, &nFlags, (sockaddr*)&addrClient, &nLen, NULL, NULL);

switc(dwTrans)
{
case packLen:
{
WSASendTo(sock[ThreadID], &buf, 1, &dwTrans, nFlags, (sockaddr*)&userAddr,nLen, NULL, NULL);
break;
}
case loginLen:
{
userAddr = addrClient;
break;
}
defalut:break;
}
}

Posted by Berger at January 12, 2017 - 4:10 PM