PDA

View Full Version : Excel 64bit issue with Winsock UDP connection



satyendra
02-02-2011, 11:37 PM
Hi,

I have code to send and receive messages from UDP port using winsock32.dll. Which is working fine with 32bit office. When I run the same code in 64bit excel I am getting the error message "Error binding listener socket:10049". I tried various ports, but no use. I think it is not because of accessing invalid ports. I have a silverlight application which is accessing same ports to send and receive messages through UDP.
I am getting this error at " w_bind(ListenSocketHandle, listenAddr, SOCKADDR_IN_SIZE)" in my code

Public Sub InitializeSilverlightConnection()
ip = "224.0.0.2"
listenPort = 6000
remotePort = 6001

If (Not SocketsInitialize()) Then
MsgBox "Error initializing WinSock"
Return
End If
SendSocketHandle = w_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)

remoteAddr.sin_family = AF_INET
remoteAddr.sin_addr = inet_addr(ip)
remoteAddr.sin_port = UnsignedLongToInteger(htons(remotePort))

localHostName = GetPcName()

ListenSocketHandle = w_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
Dim listenAddr As SOCKADDR_IN
listenAddr.sin_family = AF_INET
listenAddr.sin_addr = inet_addr(localHostIP)
listenAddr.sin_port = UnsignedLongToInteger(htons(listenPort))
Dim bindResult As Long
bindResult = w_bind(ListenSocketHandle, listenAddr, SOCKADDR_IN_SIZE)
If bindResult = SOCKET_ERROR Then
MsgBox "Error binding listener socket: " & CStr(Err.LastDllError)
Call SocketsCleanup
'Return
End If

If JoinSourceGroup(ListenSocketHandle, inet_addr(ip), inet_addr(localHostIP)) = SOCKET_ERROR Then
Call SocketsCleanup
Else
Joined = True
End If
End Sub

Public Function SocketsInitialize() As Boolean
Dim WSAD As WSADATA
SocketsInitialize = WSAStartup(WS_VERSION_REQD, WSAD) = IP_SUCCESS
End Function

Private Function UnsignedLongToInteger(uLong As Long) As Integer
If uLong > 32767 Then
UnsignedLongToInteger = uLong - 65536
Else
UnsignedLongToInteger = uLong
End If
End Function

Private Function JoinSourceGroup(socketHandle As Long, GroupAddress As Long, InterfaceAddress As Long) As Long
Dim Error As Long
Dim imr As ip_mreq

imr.imr_multiaddr = GroupAddress
imr.imr_interface = InterfaceAddress

Error = setsockopt(socketHandle, IPPROTO_IP, IP_ADD_MEMBERSHIP, imr, LenB(imr))

If Error = SOCKET_ERROR Then
MsgBox "Error Setting IP_ADD_MEMBERSHIP: " & CStr(Err.LastDllError)
End If

JoinSourceGroup = Error
End Function

I am stuck here with this issue. Can any one help me sort out this issue. Thanks in advance

Satyendra