Click to See Complete Forum and Search --> : Connect to ip?
Paul M
Dec 25th, 2006, 01:18 PM
You will need to use the Winsock1.SendData method.
DigiRev
Dec 25th, 2006, 02:14 PM
Tanks It work but now i want to send data over the connection please give me an example. I have read some but i dident mange them to work. And when i connect it just says 127.0.0.1 and that aren't my local ip.
There are articles & tutorials all over the net explaining how to use the Winsock control.
To send data you'd put:
Winsock1.SendData "Data here"
Make sure the Winsock is connected or you will get an "invalid state" error. You could even do a simple check with an If statement:
If Winsock1.State = sckConnected Then Winsock1.SendData "Data here"
If 127.0.0.1 is showing up as your local IP then that means you either put "127.0.0.1" or "localhost" as the RemoteHost in the Connect statement.
To connect to yourself you can just use:
Winsock1.Connect Winsock1.LocalIP, 1234
AxeFestis
Jul 2nd, 2007, 07:37 AM
How do i connect to an ip whit winsock? Or something like that in 2005?
Sorry if this i a n00b question :sick:
AxeFestis
Jul 2nd, 2007, 07:39 AM
And can i show on the server if there are any connected?
DigiRev
Jul 2nd, 2007, 05:18 PM
To connect to an IP (using TCP) use this code:
Winsock1.Close
Winsock1.Connect "123.123.123.123", 1234
Where "123.123.123.123" is the IP address and 1234 is the port number.
That will be in your client project.
On the server project, you'd have a Winsock control and the code would be something like this:
Private Sub Form_Load()
Winsock1.Close
Winsock1.LocalPort = 1234
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
Me.Caption = "Connected [" & Winsock1.RemoteHostIP & "]"
End Sub
That's just for accepting one connection at a time. For multiple connections, you'd have to use a control array of Winsocks on the server side.
AxeFestis
Jul 3rd, 2007, 04:05 AM
Tanks It work but now i want to send data over the connection please give me an example. I have read some but i dident mange them to work. And when i connect it just says 127.0.0.1 and that aren't my local ip.
AxeFestis
Jul 3rd, 2007, 08:02 AM
OK, and how do you receive the data i tired get data but when i try to transfer it to a label or something it wont work could you give an example
AxeFestis
Jul 3rd, 2007, 08:07 AM
Could somebody give a hole server client sample whit winsock, Thanks
DigiRev
Jul 3rd, 2007, 09:25 AM
Could somebody give a hole server client sample whit winsock, Thanks
No. There are plenty of tutorials and example code on the net that you can learn from.
Sometimes you just have to do SOMETHING yourself.
AxeFestis
Jul 4th, 2007, 06:00 AM
Sorry for ASKING in the forum then
DigiRev
Jul 4th, 2007, 02:45 PM
I wasn't trying to sound rude, it's just there's so many people here expecting all the code to be given to them. I don't think that's what you were wanting.
I can write a very basic client/server example if you like but really, there are so many examples on the internet.
Take a look at these:
http://www.pscode.com/vb/scripts/BrowseCategoryOrSearchResults.asp?txtCriteria=winsock+tutorial&blnWorldDropDownUsed=TRUE&txtMaxNumberOfEntriesPerPage=10&blnResetAllVariables=TRUE&lngWId=1&B1=Quick+Search&optSort=Alphabetical
CVMichael
Jul 4th, 2007, 03:43 PM
Could somebody give a hole server client sample whit winsock, Thanks
To send files:
http://www.vbforums.com/showthread.php?t=377648
Chat program:
http://www.vbforums.com/showpost.php?p=1639292&postcount=43
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.