PDA

View Full Version : Winsock for VB6


VB_Programmer_Person
09-20-2006, 07:08 AM
hello.

I am an alright VB6 programmer, and would like to learn how to use winsock and comunicate with other computers via an IP adress.

Thanks,

VB_Programmer_Person

FlawedSin
09-21-2006, 02:23 AM
you need to look up a guide..

more less you have the server listen... then you have the client connect

after that you send and receive the data and interpret it

like I said look up a guide

VB_Programmer_Person
09-21-2006, 09:55 AM
yeah, I found a few, but I still don't quite get it>:( - can someone tell me whats wrong with this code?:

Private Sub Command1_Click()
Winsock1.SendData "Text1.Text"
End Sub

Private Sub Form_Load()
Winsock2.Listen

Winsock1.Connect Text3.Text, 1234
End Sub

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Winsock2.GetData Text2.Text
End Sub

FlawedSin
09-21-2006, 04:09 PM
yeah, I found a few, but I still don't quite get it>:( - can someone tell me whats wrong with this code?:

Private Sub Command1_Click()
Winsock1.SendData "Text1.Text"
End Sub

Private Sub Form_Load()
Winsock2.Listen

Winsock1.Connect Text3.Text, 1234
End Sub

Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Winsock2.GetData Text2.Text
End Sub

wait do you have the server and client stuff altogether? whats the point of that theres no need to connect then lol.

Anyways split them up. And Winsock doesnt need 2 different names... you can have it the same throughout. I will give you basic code to connect to 1 client to 1 server.


CLIENT

Private Sub cmdConnect_Click()
Winsock.RemoteHost = "127.0.0.1" ' this is the Ip of the server 127.0.0.1 loops back to your own computer
Winsock.RemotePort = 8765 ' this is the port it must be the same as the server
Winsock.Connect ' connect!
End Sub

Private Sub cmdSend_click()
Winsock.SendData Text1.Text ' sends the data in the textbox
End Sub

Private Sub winsock_DataArrival(ByVal bytesTotal As Long)

Dim incomingData As String 'this stores the data we receive

Winsock.GetData incomingData ' this stores the data in the variable we set above
End Sub

I will do server later I gotta go take a stat test here like right now.

Stephen
09-23-2006, 09:51 AM
Better to make your connection input~

port = inputbox("Enter port name here")
host = inputbox("Enter host ip here")
winsock1.connect host, port

Same with the server hosting
port = inputbox("Enter port to host on")
winsock1.localport = port
winsock1.listen

And another thing which is quite useful
Ina cmd click put this~
msgbox "Your ip address is " & winsock1.localip
or something along those lines