Who's Online
61 user(s) are online (
44 user(s) are browsing
Forums )
Members: 2
Guests: 59
TearsOfMe ,
Petrol ,
more...
Headlines
vulkanos4.lha - development/library/graphics
Mar 20, 2026
imp3handler.lha - network/misc
Mar 20, 2026
amigadiskbench.lha - utility/benchmark
Mar 20, 2026
acm.lha - audio/convert
Mar 19, 2026
avalanche.lha - utility/archive
Mar 18, 2026
vintagesongplayer.lha - audio/play
Mar 16, 2026
hwp_avcodec.lha - library/hollywood
Mar 16, 2026
depscan.lha - utility/shell
Mar 16, 2026
amiarcadia.lha - emulation/gamesystem
Mar 12, 2026
imp3.lha - audio/play
Mar 11, 2026
Topic options
View mode
Newest First
Need help whit socket programming.
Posted on:
2009/10/24 23:28
#1
Home away from home
Joined: 2006/11/20 16:26Last Login
: Yesterday 9:25
From Norway
Group:
Registered Users
need more help whit socket programming, Can't get bind() or accept() to work whit in CreateNewProcess()
Edited by LiveForIt on 2009/10/26 22:09:22
(NutsAboutAmiga) Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
Re: Need help whit socket programming.
Posted on:
2009/10/25 0:20
#2
Not too shy to talk
Joined: 2006/12/1 23:50Last Login
: 3/3 9:57
From Denmark
Group:
Registered Users
@LiveForIt Its very importent that you open the bsdsocket library in the same process that you need to call the recv/send/bind and so on commands. RWO
Re: Need help whit socket programming.
Posted on:
2009/10/25 9:09
#3
Just popping in
Joined: 2006/12/22 10:43Last Login
: 1/14 5:43
From Germany
Group:
Registered Users
@LiveForIt Let me add a bit more to what RWO already said to clarify: Because of serveral technical reasons bsdsocket.lib only allows to access its socketfunctions from exactly that process, which also opened bsdsocket.lib. So if you have to use bsdsocket.lib in some child process or so, you MUST open a separate copy of bsdsocket.lib in the child process, otherwise it can't use socketfunctions via the SocketBase from the parent process. That said, you now know what is the officially recommended way of doing what you want to do. But of course there is also a not really recommended way of doing it differently... I'll leave it up to you to figure it out, because you *really* should know what you are doing if you choose the other way. BTW: All that is pretty well described in the bsdsocket.lib autodoc in the OpenLibrary() section.
AmigaOS 4 core developer
www.os4welt.de - Die deutsche AmigaOS 4 Gemeinschaft
"In the beginning was CAOS.."
-- Andy Finkel, 1988 (ViewPort article, Oct. 1993)
Re: Need help whit socket programming.
Posted on:
2009/10/25 17:27
#4
Home away from home
Joined: 2006/11/20 16:26Last Login
: Yesterday 9:25
From Norway
Group:
Registered Users
@every one Thanks for the help
(NutsAboutAmiga) Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
Re: Need help whit socket programming.
Posted on:
2009/10/26 21:55
#5
Home away from home
Joined: 2006/11/20 16:26Last Login
: Yesterday 9:25
From Norway
Group:
Registered Users
@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 );
}
(NutsAboutAmiga) Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
Re: Need help whit socket programming.
Posted on:
2009/10/28 15:35
#6
Home away from home
Joined: 2006/12/4 23:15Last Login
: Today 18:06
Group:
Registered Users
@LiveForIt
I'm not 100% sure what you're probelm is but a few things occur to whilst looking through your code.
Quote:
#define close_lib( base, interface) \ if (interface) { interface->Release(); interface = NULL; } \ if (base) { iexec -> CloseLibrary(base); base = NULL; }Ouch, don't call interface->Release()
call
IExec->DropInterface((struct Interface *)interface)
also I don;t think you need to call iexc->Obtain() / iexec->Release()
at least I never seen any example code do this, the example in CreateNewProc autodoc certainly doesn't
I notice that you call
sd = socket(PF_INET, SOCK_DGRAM, 0);
without going via your ibsd but everywhere else use ibsd->
socket() will use IBsd internaly thus won't be using your copy of it. This could cause the issue your experiencing.
Also your don't check sd for success
Re: Need help whit socket programming.
Posted on:
2009/10/28 19:55
#7
Home away from home
Joined: 2006/11/20 16:26Last Login
: Yesterday 9:25
From Norway
Group:
Registered Users
@broadblues
I have done some major bad things
“bsdbase” needs to be called “SocketBase”, ScoketBase can't be declared as global
so get_text.c has to be compiled whit the -D__NOLIBBASE__ like this:
gcc get_text . c - o get_text . o - c - D__NOLIBBASE__
after fixing this, it does obtain the socket, but never frees it, this gives me an other error,
errno = 48 from ISocket->bind(), so fixed that problem by increasing the tcp_port number, until found one that was free.
Now most of the code works:
bytes = ibsd -> recvfrom ( sd , buffer , sizeof ( buffer ), 0 , ( struct sockaddr *)& addr , & addr_len );
keeps on returning bytes == 0, and no buffer is filled.
Edited by LiveForIt on 2009/10/28 20:33:49
(NutsAboutAmiga) Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
Re: Need help whit socket programming.
Posted on:
2009/10/28 20:35
#8
Home away from home
Joined: 2006/11/20 16:26Last Login
: Yesterday 9:25
From Norway
Group:
Registered Users
@broadblues
Quote:
I notice that you call sd = socket(PF_INET, SOCK_DGRAM, 0);Your correct SD gaves bad socket, as well, if I use ibsd -> bind()
(NutsAboutAmiga) Basilisk II for AmigaOS4 AmigaInputAnywhere Excalibur and other tools and apps.
Currently Active Users Viewing This Thread:
1
(
0 members
and 1 Anonymous Users
)