Hi,
I'm not sure if this is strictly a U2 question, but since it relates to
a U2 application, I'll post here just in case...
Has anyone got any experience of the differences between sockets on
Windows 2003 and Windows 2003? We have a Windows service that listens
on a port for a connection from a UniData program. It works fine under
Win2k / Win2003, but not on Windows 2008.
Initially, the output log for the service showed the following error
when the conenction was attempted
"System.Net.Sockets.SocketException: An address incompatible with the
requested protocol was used"
A check on Google showed that this was likely down to the fact that
Win2008 uses IPv6 as default, and so I needed to change the service to
accept the correct address family, so the service code changed from:
***************************************************
byte[] bytes = new Byte[1024];
// Establish the local endpoint for the socket.
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, listenPort);
// Create a TCP/IP socket.
Socket listener = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
// Bind the socket to the local endpoint and listen for incoming
connections.
try
{
listener.Bind(localEndPoint);
listener.Listen(100);
***************************************************
To:
***************************************************
byte[] bytes = new Byte[1024];
// Establish the local endpoint for the socket.
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, listenPort);
// Create a TCP/IP socket.
Socket listener = new Socket(ipAddress.AddressFamily, SocketType.Stream,
ProtocolType.Tcp);
// Bind the socket to the local endpoint and listen for incoming
connections.
try
{
listener.Bind(localEndPoint);
listener.Listen(100);
***************************************************
(the only change being the first parameter in the Socket constructor)
I now no longer get the exception, but when UniData tries to communicate
with the service via writeSocket(), it returns with error code 14 ("The
socket has been shut down").
Oddly, the connection attempt doesn't even show in the event log for the
Windows service, although trying to connect via telnet will allow me to
send one character before shutting down, and that does show in the log.
Does anyone know what I might be missing to cause this to fail?
Thanks in advance,
Adam
This electronic message contains information from CACI International Inc or
subsidiary companies, which may be confidential, proprietary,
privileged or otherwise protected from disclosure. The information is
intended to be used solely by the recipient(s) named above. If you are not
an intended recipient, be aware that any review, disclosure, copying,
distribution or use of this transmission or its contents is prohibited. If
you have received this transmission in error, please notify us immediately
at [email protected]
Viruses: Although we have taken steps to ensure that this e-mail and
attachments are free from any virus, we advise that in keeping with good
computing practice the recipient should ensure they are actually virus free.
CACI Limited. Registered in England & Wales. Registration No. 1649776. CACI
House, Avonmore Road, London, W14 8TS.
_______________________________________________
U2-Users mailing list
[email protected]
http://listserver.u2ug.org/mailman/listinfo/u2-users