Problems with Winsock API calls

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with Winsock API calls

Esteban A. Maringolo-2
Hi,

    I'm implementing, and it's almost ready, datagram sockets support (aka
UDP), for Dolphin XP 5.1.4.

   All the API calls works fine, there is just one with which I cannot find
what's going wrong, because the result is an standard error result, and I
have no more information that this result (-1).

    The Socket method is:

DatagramSocket>>receiveDatagram: aByteArray withSenderDo: aBlock
     "Receive aByteArray from message queue, if the reception completes
successfully, executes aBlock with the receiver datagram, and the
SOCKADDR_IN of the datagram sender as arguments."

 | remoteSocketAddress result |
 remoteSocketAddress := SOCKADDR_IN new.
 result := WSockLibrary default
    recvfrom: self asParameter
    buf: aByteArray
    len: aByteArray size
    flags: 0
    from: remoteSocketAddress asParameter
    fromlen: remoteSocketAddress size.

 result = -1
  ifTrue: [self error]
  ifFalse: [aBlock value: remoteSocketAddress value: aByteArray]

What the API funcion does is put in aByteArray the datagram's bytes, and in
remoteSocketAddress complete the SOCKADDR_IN structure with the information
of the datagram sender (IN_ADDR, port and protocol family).

remoteSocketAddress should be a pointer to a SOCKADDR_IN structure, but as i
understand, it is.

I can't make it work, but if I call it with the from and fromlength zero'ed
it works fine:

WSockLibrary default recvfrom: self asParameter
     buf: aByteArray len: aByteArray size
     flags: 0
     from: 0
     fromlen: 0.

It retrieves the datagram, pero is functionally similar to
"WSockLibrary>>recv:buf:len:flags:", and doesn't retrieves the sender
address of the datagram sender, being unable to answer back to the sender.

I've looked in SDK, and in other implementations (C, C++), and to me it
should work with no errors.

--
Esteban A. Maringolo


Reply | Threaded
Open this post in threaded view
|

Re: Problems with Winsock API calls

Esteban A. Maringolo-2
Hello,

"Esteban A. Maringolo" <[hidden email]> escribió en el mensaje
news:<40c5f8b1$[hidden email]>...

>     I'm implementing, and it's almost ready, datagram sockets support (aka
> UDP), for Dolphin XP 5.1.4.

The solution was passing anSDWORD as the 'fromlen' argument of the api call.


--
Esteban.


Reply | Threaded
Open this post in threaded view
|

Re: Problems with Winsock API calls

Udo Schneider
In reply to this post by Esteban A. Maringolo-2
Esteban,

Dmitry Zamotkin wrote a UDP package and posted it to c.l.s.d. some time ago.
Take a look at the
following thread - maybe it helps:
http://groups.google.com/groups?hl=de&lr=&ie=UTF-8&threadm=9nt2r1%24m53%241%40news.demos.su&rnum=2&prev=/groups%3Fq%3DUDP%2Bgroup:comp.lang.smalltalk.dolphin%26hl%3Dde%26lr%3D%26ie%3DUTF-8%26group%3Dcomp.lang.smalltalk.dolphin%26selm%3D9nt2r1%2524m53%25241%2540news.demos.su%26rnum%3D2

CU,

Udo



"Esteban A. Maringolo" <[hidden email]> schrieb im Newsbeitrag
news:40c5f8b1$[hidden email]...
> Hi,
>
>     I'm implementing, and it's almost ready, datagram sockets support (aka
> UDP), for Dolphin XP 5.1.4.
>
>    All the API calls works fine, there is just one with which I cannot
find

> what's going wrong, because the result is an standard error result, and I
> have no more information that this result (-1).
>
>     The Socket method is:
>
> DatagramSocket>>receiveDatagram: aByteArray withSenderDo: aBlock
>      "Receive aByteArray from message queue, if the reception completes
> successfully, executes aBlock with the receiver datagram, and the
> SOCKADDR_IN of the datagram sender as arguments."
>
>  | remoteSocketAddress result |
>  remoteSocketAddress := SOCKADDR_IN new.
>  result := WSockLibrary default
>     recvfrom: self asParameter
>     buf: aByteArray
>     len: aByteArray size
>     flags: 0
>     from: remoteSocketAddress asParameter
>     fromlen: remoteSocketAddress size.
>
>  result = -1
>   ifTrue: [self error]
>   ifFalse: [aBlock value: remoteSocketAddress value: aByteArray]
>
> What the API funcion does is put in aByteArray the datagram's bytes, and
in
> remoteSocketAddress complete the SOCKADDR_IN structure with the
information
> of the datagram sender (IN_ADDR, port and protocol family).
>
> remoteSocketAddress should be a pointer to a SOCKADDR_IN structure, but as
i
> understand, it is.
>
> I can't make it work, but if I call it with the from and fromlength
zero'ed

> it works fine:
>
> WSockLibrary default recvfrom: self asParameter
>      buf: aByteArray len: aByteArray size
>      flags: 0
>      from: 0
>      fromlen: 0.
>
> It retrieves the datagram, pero is functionally similar to
> "WSockLibrary>>recv:buf:len:flags:", and doesn't retrieves the sender
> address of the datagram sender, being unable to answer back to the sender.
>
> I've looked in SDK, and in other implementations (C, C++), and to me it
> should work with no errors.
>
> --
> Esteban A. Maringolo
>
>
>