This commit is contained in:
2019-08-08 12:44:50 +02:00
parent f4c673510f
commit 82e1bf915b
638 changed files with 433536 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
Imports System.Net.Sockets
Imports System.Net
Imports System.Text
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
begin()
End Sub
Dim clientSocket As Socket
Dim byteData(1023) As Byte
Private Sub begin()
clientSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim ipAddress As IPAddress = ipAddress.Parse("192.168.0.90")
Dim ipEndPoint As IPEndPoint = New IPEndPoint(ipAddress, 8800)
clientSocket.BeginConnect(ipEndPoint, New AsyncCallback(AddressOf OnConnect), Nothing)
' endconnect(clientSocket)
End Sub
Private Sub OnConnect(ByVal ar As IAsyncResult)
Try
clientSocket.EndConnect(ar)
clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, _
New AsyncCallback(AddressOf OnRecieve), clientSocket)
Catch ex As Exception
' MsgBox("Verbindung zum Server konnte nicht aufgebaut werden!")
End Try
End Sub
Private Sub OnSend(ByVal ar As IAsyncResult)
Dim client As Socket = ar.AsyncState
client.EndSend(ar)
End Sub
Private Sub Send(ByVal msg As String, ByVal client As Socket)
Dim sendBytes As Byte() = Encoding.BigEndianUnicode.GetBytes(msg)
client.BeginSend(sendBytes, 0, sendBytes.Length, SocketFlags.None, New AsyncCallback(AddressOf OnSend), client)
End Sub
Public Function ByteArrayToTextString(ByRef Barr() As Byte) As String
Dim enc As System.Text.Encoding = Encoding.BigEndianUnicode
Return enc.GetString(Barr)
End Function
Private Sub OnRecieve(ByVal ar As IAsyncResult)
Try
Dim client As Socket = ar.AsyncState
client.EndReceive(ar)
Dim bytesRec As Byte() = byteData
Dim message As String = Encoding.BigEndianUnicode.GetString(bytesRec)
' MsgBox("FROM SERVER: " & message)
Dim b(1023) As Byte
' MsgBox("SERVER RECIEVE: " & Encoding.BigEndianUnicode.GetString(b))
byteData = b
Read(message)
clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, _
New AsyncCallback(AddressOf OnRecieve), clientSocket)
Catch ex As Exception
' MsgBox("Verbindung zum Server wurde unterbrochen!")
End Try
End Sub
Delegate Sub _Read(ByVal msg As String)
Private Sub Read(ByVal msg As String)
If InvokeRequired Then
Invoke(New _Read(AddressOf Read), msg)
Exit Sub
End If
'if richtige nsachricht
' Dim asciis As Byte() = Encoding.BigEndianUnicode.GetBytes(msg)
' Dim a As Char = msg(msg.Length - 1)
' msg = msg.Replace(a, "")
' MsgBox(msg.Length)
' MsgBox(msg(msg.Length - 1))
' MsgBox(msg(msg.Length - 1))
' MsgBox(Asc(msg(msg.Length - 1)))
' MsgBox(Asc(msg(msg.Length - 2)))
msg = msg.Replace(Convert.ToChar(0), "")
Try
MsgBox(msg)
' MsgBox("-" & msg & "-" & vbNewLine & "ConSuccess" & "-")
If msg = "ConSuccess" Then
' MsgBox("!!!!!ConSuccess --> initAufschubkonten")
Send("initAufschubkonten", clientSocket)
ElseIf msg = "Task successful" Then
MsgBox("DONE")
clientSocket.Disconnect(False)
clientSocket.Shutdown(SocketShutdown.Both)
clientSocket.Close()
'endconnect(clientSocket)'geht ned
Else
MsgBox("Was labert der Server da ?: " & msg)
clientSocket.Shutdown(SocketShutdown.Both)
clientSocket.Close()
End If
Catch ex As Exception
MsgBox("Verbindung-Fehler beim Senden")
clientSocket.Close()
End Try
' byteData = Encoding.BigEndianUnicode.GetBytes("")
End Sub
End Class