Jump to content
  • Advertisement
Sign in to follow this  


This topic is 1641 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys,

everytime I get the WSAEINVAL error in enet_socket_receive when I’m using the Client. The Server has no Problems at all.

I used different sources in the web but noone worked for me.
Using Version 1.2.5 and cant upgrade to a higher Version due to serveral reasons.

This is one version but like everytime with the same error.

#include <enet/enet.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char **argv)
    ENetAddress address;
    ENetHost *client;
    ENetPeer *peer;
    char message[1024];
    ENetEvent event;
    int eventStatus;

    // a. Initialize enet
    if (enet_initialize() != 0) {
        fprintf(stderr, "An error occured while initializing ENet.\n");
        return EXIT_FAILURE;


    // b. Create a host using enet_host_create
    client = enet_host_create(NULL, 2, 57600/8, 14400/8);

    if (client == NULL) {
        fprintf(stderr, "An error occured while trying to create an ENet server host\n");

    enet_address_set_host(&address, "localhost");
    address.port = 5119;

    // c. Connect and user service
    peer = enet_host_connect(client, &address, 2);

    if (peer == NULL) {
        fprintf(stderr, "No available peers for initializing an ENet connection");

    eventStatus = 1;

    while (1) {
        eventStatus = enet_host_service(client, &event, 50000);

        // If we had some event that interested us
        if (eventStatus > 0) {
            switch(event.type) {
                case ENET_EVENT_TYPE_CONNECT:
                    printf("(Client) We got a new connection from %x\n",

                case ENET_EVENT_TYPE_RECEIVE:
                    printf("(Client) Message from server : %s\n", event.packet->data);
                    // Lets broadcast this message to all
                    // enet_host_broadcast(client, 0, event.packet);

                case ENET_EVENT_TYPE_DISCONNECT:
                    printf("(Client) %s disconnected.\n", event.peer->data);

                    // Reset client's information
                    event.peer->data = NULL;

        printf("Say > ");

        if (strlen(message) > 0) {
            ENetPacket *packet = enet_packet_create(message, strlen(message) + 1, ENET_PACKET_FLAG_RELIABLE);
            enet_peer_send(peer, 0, packet);
Please help me.

Share this post

Link to post
Share on other sites

I have exactly the same problem. How did you fix it?


It looks like enet_socket_bind is not called because address is NULL in enet_host_create and you cant use WSARecvFrom on unbind sockets.

Edited by Lesiuk

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!