Winsock Ctrl

I am developing the client server application in which i used winsock ctrl with TCP Connection.
i 've following code segment for connection

Private Sub Command1_Click()
    ws.Close
    ws.LocalPort = CLng(Text1.Text)
    ws.Bind ws.LocalPort, ws.LocalIP
    ws.Listen
    If (ws.State = 2) Then Apnd ("Listenin")
End Sub

Private Sub ws_ConnectionRequest(ByVal requestID As Long)
    If (ws.State <> 0) Then ws.Close
    ws.Accept requestID
End Sub

the problem is,it works fine if i pass 127.0.0.1 but gives me error if i passed my PC IP(of LAN)that connection refused forcefully
can somebody help me
Thank you
LVL 5
avya2kAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

irfanazamCommented:
Hi,

You have said that want TCP Connection...But in your code you are using Bind method..Bind is always used in the case you are using UDP Connections. Your code must be like this

Private Sub Command1_Click()
   ws.Close
   ws.LocalPort = CLng(Text1.Text)
   ws.Listen
   If (ws.State = 2) Then Apnd ("Listenin")
End Sub

this will make winsock control to listen on your Local IP (your PC IP of LAN) and port specified.
0
avya2kAuthor Commented:
I refered MSDN for this and the very first line of Bind Method is as follows

Specifies the LocalPort and LocalIP to be used for TCP connections. Use this method if you have multiple protocol adapters.

0
avya2kAuthor Commented:
and Apnd is simple function to print Data
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

dc197Commented:
You are binding it to the default value of its IP:
 ws.Bind ws.LocalPort, ws.LocalIP

What local IP have you set previous to this?  
Set the bind IP address to be a given value, eg

   ws.Bind 80, "192.168.0.1"
The default value of ws.LocalIP is probably 127.0.0.1 so you are forceing it to bind to this address in the line  ws.Bind ws.LocalPort, ws.LocalIP
 


When you say you pass it "127.0.0.1" do you mean the value of Text1.Text?  This should be a port, not an IP address.

   
0
avya2kAuthor Commented:
i have not passed it through text1.text but it is constant
if i make it 127.0.0.1 then it works but if i make it 192.168.0.10 then it gives me error

localIP is default taken as 192.168.0.10 i.e. of my network IP and not 127.0.0.1

0
irfanazamCommented:
Hi,

you should read statement in MSDN, it says use Bind method if you are using multiple protocols adapters. Are you using these. i am sure not.

have you tried the code i mentioned in my first comment. try it. i guarantee that i will server the purpose if you are not using multiple protocol adapters.
0
avya2kAuthor Commented:
I also tried without Bind but not worked
0
avya2kAuthor Commented:
i tried it but it not worked
it gives same error that connection forcefully refused
0
avya2kAuthor Commented:
anybody there
0
CleanupPingCommented:
avya2k:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
dc197Commented:
"Connection forcefully rejected" means that the remote host said "no way" when you tried to connect to it.  This is not anything wrong with your code.  This is something wrong at the other machine.

Check that the other machine has the service you want to connect to (eg an HTTP server) running.  

If you get "connection timed out", it means either there is no computer at the address you're connecting to or its running a firewall that is set up to ignore your request to that port (rather than say "no you cannot connect" and give a "forcefully rejected" error).

Why not split the points between those people who helped you before CleanUpPing recommended you close the question?  That is, dc197 (me) and irfanazam.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
avya2kAuthor Commented:
Can you tell me if there is some special setting in Win2k
to block the port
I am not using any firewall or equivalent appln.
Does this can be due to Antivirus (McAffee / Norton)
0
avya2kAuthor Commented:
Can you tell me if there is some special setting in Win2k
to block the port
I am not using any firewall or equivalent appln.
Can this be due to Antivirus (McAffee / Norton)
0
dc197Commented:
You CAN block ports in Win2k alone, without any third party software, you can use Internet Connection Sharing (http://www.practicallynetworked.com/sharing)

But it is easier to use a personal firewall (http://www.kerio.com/kpf_home.html)

Your AV program may have some simple firewall abilities.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.