Hi All -
Using Visual Studio 2005 Pro...
I'm going to ask a question about some code I inherited. I'm trying
to learn how it works so please bear with me if my question doesn't
make sense. I have a program that acts as a socket server - a
middleman between a fortran dll and several client apps. Runs fine on
XP. Threw it on a Vista machine the other day and it kept bombing
out.
After a bit of debugging the code on the Vista machine and the XP
machine, I discovered the difference and I seem to have solved my
problem, though I don't really understand it.
This server waits for a connection and then uses asychronous
operations to
accept the connection, get data from the connected client,
performs the requested functions (calls fortran.DLL) and
returns output to the client.
It then disconnects from the client and waits for another client.
----------------------------------------------------------------------------------------------------------------------
Public Shared Sub Main()
'Get port from registry
Dim iPort As Int16 = My.Settings.port
'Make seperate thread for system tray icon
Dim thrCtl As New BackgroundWorker
AddHandler thrCtl.DoWork, AddressOf Notify_Handler
thrCtl.RunWorkerAsync()
' Data buffer for incoming data.
Dim bytes() As Byte = New [Byte](1023) {}
' Establish the local endpoint for the socket.
Dim ipHostInfo As IPHostEntry = Dns.GetHostEntry("localhost")
Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
Dim localEndPoint As New IPEndPoint(ipAddress, iPort)
' Create a TCP/IP socket.
Dim listener As New Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp)
' Bind the socket to the local endpoint and listen for
incoming connections.
listener.Bind(localEndPoint)
listener.Listen(100)
more code
more code
more code
----------------------------------------------------------------------------------------------------------------------
My question refers to the line:
Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
In XP, so far as I can tell, the .AddressList returned is always
length = 1 (no matter which machine I run it on), so subscript 0
always contains the information I need to continue. However, on my
Vista machine (one data point, I know, I know), the .AddressList
returned is length = 2, and the subscript 1 contains the information I
need to continue.
So to make this run in Vista I just changed a single character, the
zero to a one, and everything works.
Dim ipAddress As IPAddress = ipHostInfo.AddressList(1)
So I'm not really even sure what question to ask here. I guess, why
might I get length 1, and when I do, how can I figure out which one
I need? Try a novice in this particular area of VB.NET. MSDN docs
are pretty confusing. I'm not sure if this is even an XP vs Vista
issue, or maybe it's not OS dependent and I'm missing some other key
detail.
Thanks in advance for any help.