server & client test

This commit is contained in:
Carl-Benedikt Krüger 2011-07-12 14:39:23 +02:00
parent 6a7c323511
commit 9d51e282da
2 changed files with 50 additions and 5 deletions

View file

@ -153,13 +153,11 @@ int network_init(void)
kprintf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
mmnif_open();
kprintf("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
return 0;
#if 0
// return 0;
#if defined(CONFIG_LWIP)
// Initialize lwIP modules
lwip_init();
// lwip_init();
#endif
#if defined(CONFIG_LWIP) && (defined(CONFIG_PCI) || defined(CONFIG_ROCKCREEK))
@ -167,5 +165,4 @@ int network_init(void)
#else
return 0;
#endif
#endif
}

48
kernel/shell.c Normal file
View file

@ -0,0 +1,48 @@
#include "shell.h"
#include "server.h"
#include "client.h"
static Server srv;
static int emac_id = -1;
static Client cli;
void shell_on_connect(ServerEventArgs* e)
{
if (srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr > 0xC0A80031 || srv.ConnectionsAddr[e->ClientID].sin_addr.s_addr < 0xC0A80001)
emac_id = e->ClientID;
kprintf("link engaged\n");
}
void shell_on_disconnect(ServerEventArgs* e)
{
kpritnf("connection lost from %s:%d",inet_ntoa(sender->ConnectionsAddr[e->ClientID].sin_addr),ntohs(sender->ConnectionsAddr[e->ClientID].sin_port));
}
void shell_on_read(ServerEventArgs* e)
{
if (emac_id != -1 && e->ClientID != emac_id)
srv_sendBuffer(&srv,emac_id,e->pBuffer,e->dwLen);
// else commandos oder so
}
void shell_init(int srv_or_cli)
{
if (srv_or_cli)
{
server_init(&srv,5555,49);
srv._OnConnect = shell_on_connect;
srv._OnDisconnect = shell_on_disconnect;
srv._OnRead = shell_on_read;
}
else
{
cli_init(&cli);
while (cli_ConnectTo(&cli,"192.168.0.1",5555,0));
sleep(1);
}
}