Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

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
0
avya2k
Asked:
avya2k
  • 8
  • 3
  • 2
  • +1
1 Solution
 
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
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

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 8
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now