Problem with socket.send

otherside

Centurion
Joined
Mar 16, 2003
Messages
127
Location
UK - Greece
Code:
        Dim StrGet As String = "user otherside"
        Dim ByteGet As Byte() = ASCII.GetBytes(StrGet)

        Dim Str As Byte() = Encoding.ASCII.GetBytes("USER Oth")
        Dim RBytes(256) As Byte
        Dim HostCon As New IPEndPoint(IPAddress.Parse("192.168.0.1"), 21)

        Dim Soc As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
        Soc.Connect(HostCon)
        If Soc.Connected Then
            Soc.Receive(RBytes, RBytes.Length, SocketFlags.None)
            Dim msg As String = Encoding.ASCII.GetString(RBytes)
            MessageBox.Show(msg)

            Soc.Send(Str, Str.Length, SocketFlags.None)

            MessageBox.Show("Data Sent")
        End If
Ok this is the code,
On one hand it works, (compiles and runs) but the data that sends never get to the server.
any idea what's wrong? or any alternative solution ?
thanks guys
 
I take it your creating a ftp client if so your commands to the server need to end with a caridge return and linefeed so encode the send string like the following...

Visual Basic:
Dim Str As Byte() = Encoding.ASCII.GetBytes("USER Oth" & VbCrLf)

also the socket will wait forever at the point

Visual Basic:
Soc.Receive(RBytes, RBytes.Length, SocketFlags.None)

unless the server sends data. try tracing through the code using the step debugger

Andy
 
Back
Top