Citat:
Ursprungligen postat av call3
Tjo allihopa.
Jag har ftt lite problem. jag skulle behva knpa ihop ngot fr att gra en klient/server program. men d jag inte kan ngot om ntverksanslutningar i vb.net och inte hittar ngra bra tutorials p ntet. s jag skulle behva lite hjlp om ngon orkar!
det jag behver r en guide/exempelkod p hur man skapar en anslutning frn en klient till en server. personen ska kunna skicka ett kommando och det ska hamna i en string p servern.
Ngon som orkar hjlpa mig.
Cyah // call3
Citat:
mports System.Net.Sockets
Imports System.Text
Class TCPCli
Shared Sub Main()
Dim tcpClient As New System.Net.Sockets.TcpClient()
tcpClient.Connect("127.0.0.1", 8000)
Dim networkStream As NetworkStream = tcpClient.GetStream()
If networkStream.CanWrite And networkStream.CanRead Then
' Do a simple write.
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there")
networkStream.Write(sendBytes, 0, sendBytes.Length)
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient.ReceiveBufferSize) As Byte
networkStream.Read(bytes, 0, CInt(tcpClient.ReceiveBufferSize))
' Output the data received from the host to the console.
Dim returndata As String = Encoding.ASCII.GetString(bytes)
Console.WriteLine(("Host returned: " + returndata))
Else
If Not networkStream.CanRead Then
Console.WriteLine("cannot not write data to this stream")
tcpClient.Close()
Else
If Not networkStream.CanWrite Then
Console.WriteLine("cannot read data from this stream")
tcpClient.Close()
End If
End If
End If
' pause so user can view the console output
Console.ReadLine()
End Sub
End Class
ett litet exempel