Jump to content
xisto Community
Sign in to follow this  

Winsock Problems! Can someone help me with it?

Recommended Posts

I'm working on creating a packet sniffer, but it's not exactly working.

Private Sub Form_Load()Winsock.RemoteHost = ""Winsock.LocalPort = 0Winsock.ListenWinsock1.RemoteHost = "cokestudios2.cokemusic.com"Winsock1.RemotePort = 80Winsock1.ConnectEnd SubPrivate Sub Winsock_DataArrival(ByVal bytesTotal As Long)Dim data As StringWinsock.GetData dataText1.Text = data + Text1.TextEnd Sub

That's the code I'm using as of now, Winsock is the client and Winsock1 is the server. I'm extremely new to the winsock component, so there's probably a few errors that I made. I'm also running another form that is connecting to a file on the server that I'm trying to sniff the packets from.

Any help will be greatly appreciated, thanks.

Share this post

Link to post
Share on other sites

Hey... Sorry for such late reply, I had health problems, and wasn't near my computer...

When you said Winsock is a client, and Winsock1 is a server, that's ok, but then you swapped functionality, In your code, Winsock is a server, and Winsock1 is a client... But, that's irrelevant for now...

Now... This is the problem area in your code... This line is telling Winsock control, to listen on ANY port, meaning, random port Winsock chooses... May be 80, may be 110, may be 20891... And it increases by one, every time you start your project...

Winsock.LocalPort = 0Winsock.Listen

Then, there are some more modifications to do... Firstly, you set RemoteHost property to the address ""... This can be a valid address, but, as my predecessors, I think you wanted to use "", wich is the address for localhost (your computer, that is). But, the main thing you are not getting any result is the line:

Winsock1.RemoteHost = "cokestudios2.cokemusic.com"

Here, you are setting the RemoteHost property to some host, that requires connection to the Internet, in order to connect... Since the best learning method is by trial and error, and with help of examples, I'll give tou the correct version of your code:

Winsock will be the server
Winsock1 will be the client

Here's the code
Private Sub Form_Load()' *** Initialize server componentWinsock.LocalPort = 80 ' *** Set the port number, on wich we will be listening for connectionsWinsock.Listen ' *** Start listening for connections' *** Initialize client componentWinsock1.RemoteHost = "" ' *** Set the address of the computer we are connecting toWinsock1.RemotePort = 80 ' *** Set the port number on wich we are trying to connectWinsock1.Connect ' *** ConnectEnd SubPrivate Sub Winsock_ConnectionRequest(ByVal requestID As Long)' *** Here, we accept incoming connectionsWinsock.Close ' *** Close the server component, so we can accept connectionWinsock.Accept requestID ' *** Accept the incoming connectionEnd SubPrivate Sub Winsock1_DataArrival(ByVal bytesTotal As Long)Dim Data As StringWinsock1.GetData dataText1.Text = Data & vbCrLf & Text1.TextEnd Sub

I'm sure you already found some examples on the net, but here :) Hope it helped...

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.