Quote:
Originally Posted by Hatz~
The problem is i dont really know anything about TCP connections and that kind of stuff so i have no idea what code to write x). I've been playing a bit on autoit with the API provided by BladeTiger12 and i have one question, how can i send x packet to 1 client and y packet to second client?
|
I'm using VB.NET
This is my code (not mine but i use it XD)
Code:
Imports System.Net
Module TCP
Dim TCPClientz As Sockets.TcpClient
Dim TCPClientStream As Sockets.NetworkStream
Function ConnectTCP(IP As String, Port As String) As Boolean
On Error GoTo ConnectionError
TCPClientz = New Sockets.TcpClient(IP, Port)
TCPClientStream = TCPClientz.GetStream()
ConnectTCP = True
Exit Function
ConnectionError:
ConnectTCP = False
End Function
Sub SendToPacketLogger(Packet As String)
Dim sendbytes() As Byte = System.Text.Encoding.ASCII.GetBytes(Packet)
TCPClientz.Client.Send(sendbytes)
End Sub
Function ReceiveFromPacketLogger() As String
ReceiveFromPacketLogger = ""
If TCPClientStream.DataAvailable = True Then
Dim rcvbytes(TCPClientz.ReceiveBufferSize) As Byte
TCPClientStream.Read(rcvbytes, 0, CInt(TCPClientz.ReceiveBufferSize))
ReceiveFromPacketLogger = System.Text.Encoding.ASCII.GetString(rcvbytes)
End If
End Function
End Module
The first function is used to connect to the packetlogger.
To connect you have to write:
ConnectTCP("127.0.0.1", "65656") (65656 is the port)
If you want to know if it's connected correctly you can use an if:
If ConnectTCP("127.0.0.1", "65656") = True Then ...
Now that you are connected, you can receive the packets and send them.
To receive them you must write:
STRING() = Split(ReceiveFromPacketLogger(), vbCr) (vbCr = return to line beginning)
Now you have a string with multiple lines, so you can use a loop to read them all.
Code:
For K As Integer = 0 To STRING.Length - 1
STRING(K) is the string of your packet
Next K
To send the packets you have to write:
SendToPacketLogger("1 u_s 3 1 1010") (1 u_s 3 1 1010 is the string of the packet that I want to send. It has 1 ahead because it's a SEND)
I'm not a programmer and I understood these things with Google. I hope I have explained myself well :D
You can contact me on discord if you don't understand something