Пример #1
0
void UdpClient::construct(byte * rgbCache, size_t cbCache, unsigned long msARPWait, unsigned long cARPRetries)
{
    initUdpClient();
    _msARPWait = msARPWait;
    _cARPRetries = cARPRetries;
    _cbCache = 0;
    _rgbCache = NULL;

    // if they are passing in a buffer for us to use, then lets use it.
    if(rgbCache != NULL && cbCache >= cbDatagramCacheMin)
    {
        _rgbCache = rgbCache;
        _cbCache = cbCache;
    }
}
Пример #2
0
/***	void UdpClient::close(void)
**
**	Synopsis:   
**      Closes the socket and clears the UdpClient instance;
**      Returns the instance to a just constructed state releasing
**      all resources except the user supplied datagram cache buffer
**      which will be reused if SetEndPoint is called again.
**
**	Parameters:
**      None
**
**	Return Values:
**      None
**
**	Errors:
**      None
**
**  Notes:
**
**      Returns the UdpClient instance to 
**      a state just as if the instance had just been
**      constructed. The user supplied datagram cache
**      should still be kept valid.
**
*/
void UdpClient::close(void)
{
    if(_hUDP < INVALID_UDP_SOCKET)
    {
        // remove from the UDP Cache
        ExchangeCacheBuffer(_hUDP, NULL, 0);

        // release MAL socket
        UDPClose(_hUDP);
        _hUDP = INVALID_UDP_SOCKET;
    }

    // initialize this instance of the class
    initUdpClient();
}
Пример #3
0
int main(int argc, char *argv[])
{
    if (argc < 2) {
        perror("argument less");
        exit(EXIT_FAILURE);
    }
    initGrid(argv[1]);
    int sfd;
    char ip[32];
    memset(ip, 0, 32);
    int port = 0;
    Msg msg_recv;
    memset(&msg_recv, 0, sizeof(Msg));
    if (atoi(argv[1]) == 1) {
        sfd = initUdpServer(IP, PORT);
        while (recvFrom(sfd, &msg_recv, sizeof(Msg), ip, &port) != 0) {
            hebing(&msg_recv);
            if (win(msg_recv)) {
                printf("YOU LOSE!\n");
                break;
            }
            move();
            sendTo(sfd, &msg, sizeof(Msg), ip, port);
            if (win(msg)) {
                printf("YOU WIN!\n");
                break;
            }
        }
    } else {
        sfd = initUdpClient();
        while (move(), sendTo(sfd, &msg, sizeof(Msg), IP, PORT) != 0) {
            if (win(msg)) {
                printf("YOU WIN\n");
                break;
            }
            recvFrom(sfd, &msg_recv, sizeof(Msg), ip, &port);
            hebing(&msg_recv);
            if (win(msg_recv)) {
                printf("YOU LOSE!\n");
                break;
            }
        }
    }
    close(sfd);
    return 0;
}
Пример #4
0
/***	UdpClient Constructors
**
**  Notes:
**      
**      This is made private so the user must supply a datagram cache buffer
**
*/
UdpClient::UdpClient()
{
    initUdpClient();
}