danucalovj

VB.NET Client

Jul 26th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.27 KB | None | 0 0
  1. Imports System.Net.Sockets
  2. Imports System.Text
  3. Public Class Form1
  4.     Dim clientSocket As New System.Net.Sockets.TcpClient()
  5.     Dim serverStream As NetworkStream
  6.  
  7.     Private Sub Button1_Click(ByVal sender As System.Object, _
  8.         ByVal e As System.EventArgs) Handles Button1.Click
  9.         Dim serverStream As NetworkStream = clientSocket.GetStream()
  10.         Dim buffSize As Integer
  11.         Dim outStream As Byte() = _
  12.         System.Text.Encoding.ASCII.GetBytes("Message from Client$")
  13.         serverStream.Write(outStream, 0, outStream.Length)
  14.         serverStream.Flush()
  15.  
  16.         Dim inStream(10024) As Byte
  17.         buffSize = clientSocket.ReceiveBufferSize
  18.         serverStream.Read(inStream, 0, buffSize)
  19.         Dim returndata As String = _
  20.         System.Text.Encoding.ASCII.GetString(inStream)
  21.         msg("Data from Server : " + returndata)
  22.     End Sub
  23.  
  24.     Private Sub Form1_Load(ByVal sender As System.Object, _
  25.         ByVal e As System.EventArgs) Handles MyBase.Load
  26.         msg("Client Started")
  27.         clientSocket.Connect("127.0.0.1", 8888)
  28.         Label1.Text = "Client Socket Program - Server Connected ..."
  29.     End Sub
  30.  
  31.     Sub msg(ByVal mesg As String)
  32. TextBox1.Text = TextBox1.Text + Environment.NewLine + " >> " + mesg
  33.     End Sub
  34. End Class
Advertisement
Add Comment
Please, Sign In to add comment