|
-
Feb 10th, 2007, 05:37 PM
#1
Thread Starter
Junior Member
Winsock Programming
I am an absolute beginner at network programming so please forgive any stupid questions. I am trying to build a simple application that sends a string out over a Winsock connection. I have a couple questions about Winsock programming.
1. How do I make the winsock object available in my code. I have a sample project from a friend at work where the Winsock1 object is available, but I can't seem to get that same functionality in any new project. I looked for references etc but found none. Is there an import or something like that that I have to do?
2. I want to set up a small test environmant for the Winsock app at home. What is required to make a Windows 2003 server responded to Winsock connection requests. All I need is for it to verify that I can establish the Winsock connection, I'll deal with what it does later.
Any and all help would be greatley appreciated.
-
Feb 10th, 2007, 05:43 PM
#2
Thread Starter
Junior Member
Re: Winsock Programming
I forgot to mention that I am doing all this in VB6, not my choice but that is what I have to do.
Thanks,
-
Feb 10th, 2007, 06:02 PM
#3
Thread Starter
Junior Member
Re: Winsock Programming
I found the answer to my first question but would still like info on how to make my server respond to Winsock connection requests. I haven't been able to make that work, even in code that I now works on the Internet(not my code, something I'm using to learn from)
-
Feb 10th, 2007, 06:12 PM
#4
Lively Member
Re: Winsock Programming
You Mean That It Accepts The Connection, When Someone Connects ?
-
Feb 11th, 2007, 12:19 AM
#5
Thread Starter
Junior Member
Re: Winsock Programming
Yes, I have a piece of code that looks like this:
Private Sub Command1_Click()
Winsock1.RemoteHost = "192.168.0.3"
Winsock1.RemotePort = 30521
Winsock1.Connect
End Sub
I just want to be able to get a "connected" status from Winsock. I have my Windows 2003 server at that address and I would like it to accept connections to this request from my XP system running this code.
-
Feb 11th, 2007, 09:05 AM
#6
Re: Winsock Programming
The Winsock_Connect event fires when your connection attempt is successful, so thats how you can get the status if it worked, also the State property contains the current State of the Winsock, e.g. sckConnected, sckClosed etc.
Search for some Winsock tutorials, what your trying to do is really simple. Just have an app listening on the server, and use the code you have to connect.
Don't forget to make use of the Close and Error events of the Winsock control.
-
Feb 11th, 2007, 09:48 AM
#7
Thread Starter
Junior Member
Re: Winsock Programming
I agree is looks simple but it sure seems difficult to make it actually happen. When I execute the code in my previous reply, it just sits there and never gets connected. I didn't include the loop that I use, but I built a timer and then check for winsock1.state = sckConnected every second. It never happens.
-
Feb 11th, 2007, 09:55 AM
#8
Re: Winsock Programming
Can you post the code that your using for the server program? Or are you trying to connect to an existing program thats running on the server? e.g. pop server.
in your WS close event have
winsock.close
msgbox "closed by remote side"
in WS error event:
winsock.close
msgbox Description
This will help you debug the app. If it fails to connect, the Error event is fired, and you will get a msgbox saying "connection rejected"
-
Feb 13th, 2007, 05:55 PM
#9
Re: Winsock Programming
riversr, you need a program listening on port 30521 running on your server. It can be an IIS server or just another VB6 program with a Winsock control.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Feb 15th, 2007, 10:09 AM
#10
Lively Member
Re: Winsock Programming
using winsocks depends on what type of program you want to make. you can connect by the code below:
VB Code:
Winsock1.RemoteHost = "www.myserver.com", "80"
Winsock1.Connect
but if you want to do something else then you will have to use winsock1_connect to make any request. the above code will only connect to the server but to make sure you are connected or not, you will have to code in winsock1_connect
VB Code:
Private Sub Winsock1_Connect()
'if connected then
'MsgBox "I am connected."
End Sub
however i am new in socks and i am too trying to learn from this site.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|