@Cyborg
Think I need more help, I tried to do what you where saying...
but bind fails
gcc get_text.c -o get_text.o -c
gcc chat.c get_text.o -o chat.exe -D__USE_INLINE__ -lauto -lamiga -lm
some where inside chat.c / main()
child_msg = (struct MsgPort *) CreateNewProcTags(
NP_NotifyOnDeathMessage, dmsg,
NP_Entry, server_get_text ,
NP_ExitData, process,
NP_Output, out ,
TAG_DONE);
get_text.o
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/bsdsocket.h>
#include <proto/socket.h>
extern int exit_processes;
extern int sd;
extern int ip_port;
extern struct sockaddr_in addr;
struct Node *node;
char buffer[1024];
#define open_lib( base, interface, name, ver, iname ) \
if(( base = iexec->OpenLibrary(name, ver) )) \
{ \
interface = (APTR) iexec->GetInterface(base,iname,1,0); \
} \
if (!interface) goto err;
#define close_lib( base, interface) \
if (interface) { interface->Release(); interface = NULL; } \
if (base) { iexec -> CloseLibrary(base); base = NULL; }
int32 server_get_text(STRPTR args UNUSED, int32 arglen UNUSED,
struct ExecBase *sysbase)
{
int cnt = 0;
struct ExecIFace *iexec = (APTR)sysbase->MainInterface;
struct Library *dosbase = NULL;
struct DOSIFace *idos = NULL;
struct Library *bsdbase = NULL;
struct SocketIFace *ibsd = NULL;
iexec->Obtain();
open_lib ( dosbase, idos, "dos.library", 50, "main" );
open_lib ( bsdbase, ibsd, "bsdsocket.library",4,"main");
sd = socket(PF_INET, SOCK_DGRAM, 0);
bzero(&addr, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(ip_port);
addr.sin_addr.s_addr = INADDR_ANY;
idos->Printf("OK server soon ready....\n");
if (ibsd->bind(sd, (struct sockaddr*) &addr, sizeof(addr)) == -1)
{
idos->Printf("bind error %d\n",errno);
goto err;
}
while ( ! exit_processes )
{
int bytes, addr_len=sizeof(addr);
bytes = ibsd->recvfrom(sd, buffer, sizeof(buffer), 0, (struct sockaddr*)&addr, &addr_len);
if (bytes>0)
{
buffer[bytes]=0;
idos->Printf("msg from %s:%d (%d bytes)\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port), bytes);
/*
RDetach(win_chat, ID_LOG);
if (node = AllocListBrowserNode(2,
LBNA_Column, 0,
LBNCA_CopyText, TRUE,
LBNCA_Text, "",
LBNCA_Editable, FALSE,
LBNA_Column, 1,
LBNCA_CopyText, TRUE,
LBNCA_Text, buffer,
LBNCA_Editable, FALSE,
TAG_DONE))
{
iexec->AddTail(ra_chat_list, node);
}
RAttach( win_chat,ID_LOG, ra_chat_list );
*/
}
else
{
// idos->Printf("Nothing %d (error %d)...\n",cnt,errno);
cnt = 1 - cnt;
}
idos->Delay(20);
}
ibsd->CloseSocket(sd);
idos->Printf("exit\n");
idos->Delay(20);
err:
idos->Printf("closing server\n");
idos->Delay(80);
close_lib( dosbase, idos );
close_lib( bsdbase, ibsd );
iexec->Release();
return(0);
}