Can't hear vb6 winsock connect request in C# listener

B

Bill

When vb6 Winsock.RemoteHost is set to "127.0.0.1", c# socket listener cannot hear connect request (my old vb6 winsock listener could hear it...).

Why doesn't this work, and is there a work around I can make on the C# side to hear the connect request?

-Bill
(don't reply by e-mail, the address is a fake)

______________________________
Steps to reproduce:
Start the C# Listener
Start the VB6 Listener
Run the VB6 Client from IDE
Notice at 1st breakpoint C# didn't see connect request (HERE IS THE PROBLEM)
Notice at 2nd breakpoint VB6 listener did see connect request (just to prove it works with Winsock)
Notice that if we use the computer name, C# can see the request (just to prove C# listener is working)

______________________________
VB6 Client: Create a new vb6 project and add the MS Winsock control to toolbox. Drop two on the blank form. Add this code:
Private Sub Form_Load()
Winsock1.RemoteHost = "127.0.0.1"
Winsock1.RemotePort = 1000
Winsock1.Connect
Stop

Winsock2.RemoteHost = "127.0.0.1"
Winsock2.RemotePort = 1001
Winsock2.Connect
Stop

Winsock1.Close
Winsock1.RemoteHost = Winsock1.LocalHostName
Winsock1.Connect
End Sub




______________________________
VB6 Listener: Create a new vb6 project and add the MS Winsock control to the toolbox. Drop one on the blank form. Add this code:
Private Sub Form_Load()
Winsock1.LocalPort = 1001
Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
MsgBox "Connect Request"
End Sub

______________________________
C# Listener: Create a new C# console app. Add this code:
using System;
using System.Net;
using System.Net.Sockets;

namespace ConsoleApplication23 {
class Class1 {
[STAThread]
static void Main(string[] args) {
IPEndPoint localEndPoint=null;

// NOTE: DNS lookups are nice and all but quite time consuming.
string sHostName = Dns.GetHostName();
IPHostEntry ipHostInfo = Dns.Resolve(sHostName);
IPAddress ipAddress = ipHostInfo.AddressList[0];
localEndPoint = new IPEndPoint(ipAddress, 1000);

Socket listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp );
listener.Bind(localEndPoint);
listener.Listen(10);
Console.WriteLine("Waiting");

listener.Accept();
Console.WriteLine("Connection request - press enter to continue");
Console.ReadLine();
}
}
}
 
T

Tian Min Huang

Hi Bill,

Thanks for your post. I am building a solution to check this issue and will
update you with my findings.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
T

Tian Min Huang

Hi Bill,

I reproduce the problem on my side, and now I'd like to share the following
information with you:

The reason why C# socket server cannot hear the connection requst from VB6
client is that it listens at the ip address other than 127.0.0.1. If I
changed to the following line in your code, and now it works as expected:
IPHostEntry ipHostInfo = Dns.Resolve("localhost");

Please check it on your side and feel free to let me know if you have any
problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
B

Bill

Very interesting. When I switch to localhost, I can indeed hear the local
requests, but then I cannot hear outside requests. I guess the only
behavior I've every observed (Winsock, Internet Explorer, etc.) is that
localhost and machine name can be used interchangably. It should be no
problem for me to listen to the port on both addresses though.

Thank you very much for your assistance!

-Bill.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top