PDA

Click to See Complete Forum and Search --> : Winsock


death
Nov 25th, 1999, 04:44 PM
How the hell are you suppost to use winsock??
I can draw the control but how do i send the commands over a network

john_murphy
Nov 25th, 1999, 07:23 PM
Try this???

This function is used to send data to a specific destination.

The following User Defined Type (UDT) is required:

Type sockaddr

sa_family As Integer
sa_data(14) As Byte

End Type

Where:


sa_family = For TCP/IP this should be the value of AF_INET (AF_INET = 2).
sa_data(14) = Interpretation of this data is based on sa_family. An internet address could be stored in the first 6 bytes of sa_data and the other 8 bytes could be zeroed.

The following function declaration is required:


Declare Function sendto Lib "wsock32.dll" (ByVal s As Long, ByRef buf As Any, ByVal buflen As Integer, ByVal flags As Integer, ByRef toaddr As sockaddr, ByRef tolen As Integer) As Integer


Where:


s = A descriptor identifying a connected socket
buf = A buffer for the incoming data
buflen = The length of buf
Flags = Specifies the way in which the call is made
toaddr = An optional pointer to the address of the target socket
tolen = The size of the address in toaddr

If no error occurs, sendto() returns the to number of bytes sent. This may be less than the number indicated by buflen. Otherwise, a value of SOCKET_ERROR is returned, and a specific error code may be retrieved by calling WSAGetLastError().

jimdalby
Nov 26th, 1999, 01:41 AM
Ha Ha, I dont think thats quite what he wants, John!!
Draper, get a life and do some RESEARCH. Every1 else has to, why shouldnt you? There are loads of tutorials and sample progs out there, try 1 of them. Failing that, ring knowles!

------------------
jimmy
ICQ:35813919
mail:jim@rdalby.f9.co.uk

death
Nov 26th, 1999, 04:40 AM
Get a life lamer jimdalby
yes i do know you but grow up
People are suppsed to be mature

razzaj
Nov 26th, 1999, 07:21 AM
:)
well first u have to know that there exists 2 types of protocols supported by vb
UDP and TCP ..
the difference (the simple way )
UDP : allows connections between computers but (peer to peer) no server
TCP : one computer is to be the server
and the others clients


i suggest u start with the udp protocol
it is much easier , here is a small example :


draw a winsock control ... ok .. good
right click and set the protocol property to UDP_"something" ...

1- in the form_load sub put the following code :

winsock1.remotehost = "here put the ip address of the computer u wish to connect to"
winsock1.remoteport = 1001 ' here u can choose any number given that it does not conflict with any other device.this number is the port on which the remote host will be recieving data.
winsock1.localport = 1002 ' this the port ur computer will be receving data on
winsock1.bind 1002 ' this is to bind ur port to the remote computer port


- now on the form place 2 text boxes :
and go back to the code section and paste this :


Private Sub Text2_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then
Winsock1.SendData Text2
Text2 = ""
End If

End Sub

Private Sub Winsock1_DataArrival(by val bytesTotal As Long)

Dim str As String
Winsock1.GetData str
Text1 = str

End Sub

on the other computer u should make the same program but .. bdont forget to chasge the content in the form_load just switch the port numbers and replace the ip number with the right one ....
basicaly that is it .... if u find any problem just message me back ...(coz u might )

- regards -
- razzaj -



[This message has been edited by razzaj (edited 11-26-1999).]

Jazz
Nov 26th, 1999, 07:17 PM
And this is for the "SERVER"

'for the module

Public intMax As Long

'for the form_load

Winsock1(0).LocalPort = 1001 'what ever you want!
Winsock1(0).Listen


'for the Winsock1_ConnectionRequest

If Index = 0 Then
intMax = intMax + 1
Load Winsock1(intMax)
Winsock1(intMax).LocalPort = 1001
Winsock1(intMax).Accept requestID
End If



------------------

death
Nov 27th, 1999, 06:39 AM
Thanks for the help but it keep erroring and saying that there is a syntax error in the line
Private Sub Winsock1_DataArrival(by value bytesTotal As Long)
I don't know why
Please help
Thanks

[This message has been edited by death (edited 11-27-1999).]

razzaj
Nov 27th, 1999, 08:30 AM
of course it should .. u are writing it the wrong way , in my example i wrote it wront to ... so hwere how it is to be writen :

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

.... the routine i gave u in my example before ...

End Sub

note : this example has nothing to do with what jazz wrote .. what jazz wrote is a part of the TCP protocole way to do it ... what i gave u is the UDP way to do it ...

- regards -
- razzaj -