?
Solved

Winsock Ctrl

Posted on 2003-03-11
14
Medium Priority
?
286 Views
Last Modified: 2013-11-13
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
Comment
Question by:avya2k
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
  • 2
  • +1
14 Comments
 
LVL 1

Expert Comment

by:irfanazam
ID: 8110900
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
 
LVL 5

Author Comment

by:avya2k
ID: 8110959
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
 
LVL 5

Author Comment

by:avya2k
ID: 8110967
and Apnd is simple function to print Data
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:dc197
ID: 8113058
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
 
LVL 5

Author Comment

by:avya2k
ID: 8116792
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
 
LVL 1

Expert Comment

by:irfanazam
ID: 8116965
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
 
LVL 5

Author Comment

by:avya2k
ID: 8117697
I also tried without Bind but not worked
0
 
LVL 5

Author Comment

by:avya2k
ID: 8117699
i tried it but it not worked
it gives same error that connection forcefully refused
0
 
LVL 5

Author Comment

by:avya2k
ID: 8260713
anybody there
0
 

Expert Comment

by:CleanupPing
ID: 9056462
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
 
LVL 5

Accepted Solution

by:
dc197 earned 225 total points
ID: 9059441
"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
 
LVL 5

Author Comment

by:avya2k
ID: 9068085
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
 
LVL 5

Author Comment

by:avya2k
ID: 9068092
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
 
LVL 5

Expert Comment

by:dc197
ID: 9070644
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question