简体   繁体   English

TFTP客户端(基于ENET)将无法连接到远程TFTP服务器

[英]TFTP Client (based on ENET) won't connect to remote TFTP server

I'm trying to implement a TFTP client in C (Windows, Visual Studio 2005). 我正在尝试在C(Windows,Visual Studio 2005)中实现TFTP客户端。

The TFTP client is supposed to connect to a remote TFTP server address on port 69. TFTP客户端应该连接到端口69上的远程TFTP服务器地址。

The TFTP client is using the ENET API for the networking stuff, but I can't get it to work. TFTP客户端使用ENET API来进行网络连接,但是我无法使其正常工作。

The TFTP client never switches to the 'CONNECTED' state and is stuck in 'CONNECTING' state. TFTP客户端永远不会切换到“已连接”状态,而会停留在“正在连接”状态。

When I run the native Windows TFTP client on Windows 7 (cmd, windows console), it has no problem connecting to the TFTP server and I can retrieve a remote file without any problems. 当我在Windows 7(cmd,Windows控制台)上运行本机Windows TFTP客户端时,连接到TFTP服务器没有问题,并且我可以检索到远程文件而没有任何问题。

So I must be doing something wrong in the code below and I'm hoping that somebody out there can tell me what I'm doing wrong: 因此,我肯定在下面的代码中做错了,我希望外面的人可以告诉我我做错了什么:

#include "enet.h"
#include <stdlib.h>
#include <stdio.h>

#pragma comment(lib, "Winmm.lib")
#pragma comment(lib, "Ws2_32.lib")

void main(void)
{
    ENetAddress address;
    ENetEvent thisEvent;
    ENetPeer *peer;
    ENetHost* client;
    int rc;

    memset(&thisEvent,0,sizeof(ENetEvent));

    rc = enet_initialize ();

    /* Create a TFTP client */
    client = enet_host_create(NULL, 1,1,0,0);

    /* Address and port of remote TFTP server */
    rc = enet_address_set_host (& address, "192.168.30.50");
    address.port = 69;

    /* Connect client to server */
    peer = enet_host_connect (client, & address, 1, 0);    

    while (1)
    {
        printf("State = %d | Event Type = %d\n", peer->state, thisEvent.type);
        enet_host_service (client, &thisEvent, 1000);
    }
}

From the documentation it doesn't look like this "ENet" library is for plain UDP communications. 文档中可以看出,该“ ENet”库似乎不是用于普通UDP通信的。 Rather, it implements a "single, uniform protocol layered over UDP". 相反,它实现了“在UDP上分层的单个统一协议”。 This is not the TFTP protocol, so your client is not compatible with a standard TFTP server. 这不是TFTP协议,因此您的客户端与标准TFTP服务器不兼容。

Use plain sockets instead. 请改用普通套接字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM