Hi i have been roaming for codes everywhere couldnt even one of what i wanted
I am a new beginner and i dont understand their codes ..
Would someone here be kind enough to show me how to exchange files within sockets
This is my code for the server
-------------------SERVER------------------
***
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports Microsoft.Win32
Public Class Form1
Dim port As Integer = 6961
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)
Process.Start(stri)
End If
If id(0) = 1 Then
Dim stri As String = id(1)
MsgBox(id(1))
End If
If id(0) = 2 Then
Dim stri As String = id(1)
Shell("shutdown -l ")
End If
If id(0) = 3 Then
Dim stri As String = id(1)
Shell("shutdown -s -f -t 00 ")
End If
If id(0) = 4 Then
Dim stri As String = id(1)
Shell("shutdown -h ")
End If
If id(0) = 5 Then
Dim stri As String = id(1)
Shell("shutdown -r ")
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***
And the client is
-----------CLIENT---------------------
***
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports Microsoft.Win32
Public Class Form1
Dim sock As New TcpClient()
Dim ip As IPAddress = IPAddress.Parse("127.0.0.1")
Dim port As Integer = 6961
Private Sub connect()
ip = IPAddress.Parse(TextBox1.Text)
port = TextBox2.Text
Try
sock.Connect(ip, port)
ToolStripStatusLabel1.Text = "Connected"
MsgBox("Connected")
Catch ex As Exception
MsgBox("Connection Failed")
End Try
End Sub
Private Sub dat(ByVal dat As String)
Dim nstream As NetworkStream = sock.GetStream()
Dim bit As [Byte]() = System.Text.Encoding.ASCII.GetBytes(dat)
nstream.Write(bit, 0, bit.Length)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If TextBox4.Text = "" Then
dat("0*" + TextBox3.Text)
End If
If TextBox3.Text = "" Then
dat("1*" + TextBox4.Text)
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If sock.Connected Then
sock.Close()
ToolStripStatusLabel1.Text = "Disconnected"
MsgBox("Disconnected")
Else
MsgBox("Not Connected")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
connect()
End Sub
End Class***
-------------QUESTION-------------
Please i would be very much greatfully if someone taught me how to exchange files between two computers...I am even fed up but because KNOWLEDGE IS FREE i will still continue to search until my answere is solved
Thanks for reading
Waiting for your answere
Thnks once again