Giter Site home page Giter Site logo

could not connect to server on Win10 about dyad HOT 4 CLOSED

rxi avatar rxi commented on June 17, 2024
could not connect to server on Win10

from dyad.

Comments (4)

rxi avatar rxi commented on June 17, 2024

Would you be able to provide the code to an example program which demonstrates this behaviour? Thanks.

from dyad.

Truth1987 avatar Truth1987 commented on June 17, 2024

OK here is the code of server.

#include <stdlib.h>
#include "dyad.h"

static void onData(dyad_Event *e) {
	dyad_write(e->stream, e->data, e->size);
}

static void onAccept(dyad_Event *e) {
	dyad_addListener(e->remote, DYAD_EVENT_DATA, onData, NULL);
	dyad_writef(e->remote, "Echo server\r\n");
}

static void onListen(dyad_Event *e) {
	printf("listen: %s\n", e->msg);
}

int main(void) {
	dyad_init();

	dyad_Stream *serv = dyad_newStream();
	dyad_addListener(serv, DYAD_EVENT_ACCEPT, onAccept, NULL);
	dyad_addListener(serv, DYAD_EVENT_DATA, onData, NULL);
	dyad_addListener(serv, DYAD_EVENT_LISTEN, onListen, NULL);
	dyad_listen(serv, 8800);

	while (dyad_getStreamCount() > 0) {
		dyad_update();
	}

	dyad_shutdown();
	return 0;
}

then, the following code is client.

#include <stdlib.h>
#include "dyad.h"

static void onConnect(dyad_Event *e) {
	printf("connected: %s\n", e->msg);
}

static void onData(dyad_Event *e) {
	printf("%s", e->data);
}

static void onError(dyad_Event *e) {
	printf("error: %s\n", e->msg);
}

static void onTimeout(dyad_Event *e) {
	printf("timeout: %s\n", e->msg);
}

int main(void) {
	dyad_init();

	dyad_Stream *s = dyad_newStream();
	dyad_addListener(s, DYAD_EVENT_CONNECT, onConnect, NULL);
	dyad_addListener(s, DYAD_EVENT_DATA, onData, NULL);
	dyad_addListener(s, DYAD_EVENT_ERROR, onError, NULL);
	dyad_addListener(s, DYAD_EVENT_TIMEOUT, onTimeout, NULL);
	//dyad_connect(s, "time-nw.nist.gov", 13);
	dyad_connect(s, "127.0.0.1", 8800);

	while (dyad_getStreamCount() > 0) {
		dyad_update();
	}

	dyad_shutdown();
	return 0;
}

from dyad.

karl2016 avatar karl2016 commented on June 17, 2024

int dyad_listenEx(
dyad_Stream *stream, const char *host, int port, int backlog
) {
struct addrinfo hints, *ai = NULL;
int err, optval;
char buf[64];
dyad_Event e;

/* Get addrinfo */
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;

because dyad_listenEx ai_family is AF_UNSPEC, socket addr may format to ip_v6. so ipv4 addr "127.0.0.1" cannot connect it.
solution: change hint.ai_family to AF_INET both in function "dyad_listenEx" and "dyad_connect", connect "127.0.0.1" will be work .

from dyad.

GRASBOCK avatar GRASBOCK commented on June 17, 2024

@karl2016 It worked for me, but wouldn't that prevent you from using the ipv6? Also for some reason, when i used the ipv6 address i found using my ipconfig command in the commandline it said , that it couldn't resolve the host (before i changed it to AF_INET)

from dyad.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.