简体   繁体   中英

Connection issue in win7 using vb.net socket programming

I am using socket programming in vb.net to create a server client remoting application. The problem occurs when I use both the client and server in a win 7 box. It works fine for win xp or cross-platform communication (eg win xp to win 7). Below are the codes used at the client and server end:

Client:

Dim ips As IPAddress() 

ips = Dns.GetHostAddresses(HostName)

For index = 0 To ips.Length - 1         

Next index

===========================================================

private sub sendFile(byval ip as string)

Dim client As TcpClient = Nothing client = New TcpClient(ips(index).ToString, 8000) 

    'Code to send file

End sub

Server:

Dim Listener As TcpListener = Nothing
Listener = New TcpListener(IPAddress.Any, 8000)
Listener.Start()

 Dim client As TcpClient = Nothing
        Dim netstream As NetworkStream = Nothing

                If Listener.Pending() Then
                client = Listener.AcceptTcpClient()
                netstream = client.GetStream()

When running both client and server on win 7 the error below is thrown:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Please help me to figure out what the problem is. Is it the level of permissions that win 7 has?

If you would consider doing this in c# have you checked out the open source communication framework, networkComms.net? No point trying to reinvent the wheel.

Below is the issue and the solution for it:

  1. Issue:

    Win 7 comes with ip v6. So whenever we are using Dns.GetHostAddresses(hostname), it returns all ip addresses associated to the host (both ip v4 & ip v6). Using this ip v6 address with functions for ip v4 compatibility created problem.

  2. Solutions:

    Whenever using Dns.GetHostAddresses(hostname), check for ip v4.

     if (ObjTemp.AddressFamily.ToString() == ProtocolFamily.InterNetwork.ToString()) 

Hope this would help others working on socket programming. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM