By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,053 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,053 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.Strea m, ProtocolType.Tcp );
listener.Bind(localEndPoint);
listener.Listen(10);
Console.WriteLine("Waiting");

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

Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

Nov 22 '05 #2

P: n/a
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.

Nov 22 '05 #3

P: n/a
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.
Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.