[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-users] Problem with netconn_connect
From: |
olivier . hachet2 |
Subject: |
[lwip-users] Problem with netconn_connect |
Date: |
Wed, 25 Aug 2004 17:46:25 +0200 |
Hi all,
I try to send the famous "hello world" between two remote machines on linux.
I have programmed a server on tap0 at ipaddr 192.168.0.2, I open a socket
with the netconn API and I wait for a connection on port 19. When somebody
is connected, the server shall send "Hello world!". So, after having
launched the server, I try on linux
# telnet 192.168.0.2 19
I receive the message. I am happy.
So I wrote a client that tries to connect to the same address on the same
port with the APIs and it can't connect to it. I have an error -3 on
netconn_connect.
In fact, I have the same problem if I work on 1 local machine.
Thanks to help me ASAP.
Olivier
Here is the piece of code of the server:
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done, &sem);
sys_sem_wait(sem);
sys_sem_free(sem);
IP4_ADDR(&gw, 192,168,0,1);
IP4_ADDR(&ipaddr, 192,168,0,2);
IP4_ADDR(&netmask, 255,255,255,0);
netif_set_default(netif_add(&netif_unix, &ipaddr, &netmask, &gw, NULL,
tapif_init, tcpip_input));
sleep(4);
test_init();
sys_timeout(5000, tcp_timeout, NULL);
with test_init function:
connection = netconn_new(NETCONN_TCP);
netconn_bind(connection, NULL, 19);
netconn_listen(connection);
while (1) {
printf("Waiting for a connection... !\n");
new_connection = netconn_accept(connection);
printf("server got connection !\n");
sleep(10);
netconn_write(new_connection, "Hello world!\n", 14, NETCONN_COPY);
}
netconn_delete(new_connection);
netconn_delete(connection);
The client side code is:
sys_init();
mem_init();
memp_init();
pbuf_init();
tcpdump_init();
sem = sys_sem_new(0);
tcpip_init(tcpip_init_done, &sem);
printf("test socket!!\n");
if (inet_aton("192.168.0.2", (struct in_addr *)&addr) == -1)
{
printf("Error on address syntax.\n");
}
printf("try to open a socket...\n");
connection = netconn_new(NETCONN_TCP);
netconn_bind(connection, &addr, 19);
printf("bind\n");
err = netconn_connect(connection, &addr, 19);
if (err != ERR_OK)
{
fprintf(stderr, "error %s\n", lwip_strerr(err));
netconn_delete(connection);
connection = NULL;
exit(1);
}
printf("connect done\n");
while ((buf = netconn_recv(connection)) != NULL) {
printf("netconn_recv n");
printf("Received from port:%d", buf->fromport);
netbuf_data(buf, &msg, &len);
printf("Received data:%s", msg);
}
return 0;
- [lwip-users] Problem with netconn_connect,
olivier . hachet2 <=