Hello, I have been working with some code to try send and receive data, but I can't figure it out how I should do.
I used this code that I found in som thread here
Isn't "Private Sub DoRead" a receive function? And how shall I do so my server connect to an other client so I can send data to it? How shall the other client listen on a specific port and receive data from the server? Maby im not even going to use UDP? I don't know. If you have any server/client code please submit it, I only have som code in vb 6 but its much difference in socketing.PHP Code:Public Class Client
Private Client As Net.Sockets.UdpClient
Public Event ClientReceived(ByVal Data As String)
Public Event ClientError(ByVal Number As Long, ByVal Description As String)
Public Event ServerConnected()
Public ReadOnly Property Socket() As Net.Sockets.UdpClient
Get
Return Client
End Get
End Property
Public Sub Connect(ByVal HostName As String, ByVal Port As Integer)
If Port = 0 Then
Err.Raise(44, "The port to connect to was not set")
End If
If HostName = vbNullString Then
Err.Raise(45, "The hostname to connect to was not set")
End If
Client = New Net.Sockets.UdpClient(HostName, Port)
DoRead()
End Sub
Private Sub DoRead()
Dim ByteArray(Client.Client.ReceiveBufferSize) As Byte
Do
Client.Client.Receive(byteArray, Client.Client.ReceiveBufferSize, Net.Sockets.SocketFlags.None)
RaiseEvent ClientReceived(System.Text.Encoding.Default.GetString(ByteArray))
Loop
End Sub
Public Sub Send(ByVal Data As String)
Dim Buffer() As Byte
Buffer = System.Text.Encoding.ASCII.GetBytes(Data)
Client.Send(Buffer, Buffer.Length)
End Sub
End Class
//Fredde




Reply With Quote