Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. help on socket programming in vb.net

help on socket programming in vb.net

Scheduled Pinned Locked Moved Visual Basic
csharpsysadmindebugginghelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    boy212
    wrote on last edited by
    #1

    pls help me. i wonder why my server cannot send a message to my client and my client cannot read from server. anyone pls help me to debug or give me tip to do it by showing wats the command to write.My deadline for this project is comong soon. Pls help me. thanks a lot. here is my source code server: Imports System.Net Imports System.Net.Sockets Imports System.Threading Imports System.IO Imports System.Text Public Class Form1 Inherits System.Windows.Forms.Form Private Client As TcpClient Private Listener As Socket Private RemotePort As Integer = 1337 Private RemoteHost As String = "localhost" Dim add As IPAddress = IPAddress.Parse("220.255.41.189") Public Shared Connected As New ManualResetEvent(False) #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub blisten_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles blisten.Click Listener = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Listener.Blocking = False Listener.Bind(New IPEndPoint(add, RemotePort)) Listener.Listen(1) ListBox1.Items.Add("Waiting for connection...") Listener.BeginAccept(New AsyncCallback(AddressOf AcceptConnection), Listener) End Sub Public Sub AcceptConnection(ByVal ar As IAsyncResult) ListBox1.Items.Add("Connection established.") Connected.Set() Dim serverSock As Socket = CType(ar.AsyncState, Socket) Dim clientSock As Socket = serverSock.EndAccept(ar) Dim buffer(1024) As Byte While True If (clientSock.Poll(100, SelectMode.SelectRead)) Then Dim count As Integer = clientSock.Receive(buffer) ListBox1.Items.Add(System.Text.Encoding.ASCII.GetString(buffer, 0, count)) End If End While End Sub Private Sub bsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bsend.Click Dim Stream As NetworkStream = Client.GetStream() Dim dataSend As [Byte]() = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text) 'Send Message Stream.Write(dataSend, 0, dataSend.Length) Stream.Flush() End Sub End Class my client source code: Imports System.Net Imports System.Net.Sockets Imports System.Threading Imports System.IO Imports System.Text Public Class Form1 Inherits System.Windows.Forms.Form Private Client As TcpClient Private Listener As Socket Private RemotePort As Integer = 1337 Private RemoteHost As String = "localhost" Dim add As IPAddress = IPAddress.Parse("220.255.41.189") Public Shared Connected As Ne

    M 1 Reply Last reply
    0
    • B boy212

      pls help me. i wonder why my server cannot send a message to my client and my client cannot read from server. anyone pls help me to debug or give me tip to do it by showing wats the command to write.My deadline for this project is comong soon. Pls help me. thanks a lot. here is my source code server: Imports System.Net Imports System.Net.Sockets Imports System.Threading Imports System.IO Imports System.Text Public Class Form1 Inherits System.Windows.Forms.Form Private Client As TcpClient Private Listener As Socket Private RemotePort As Integer = 1337 Private RemoteHost As String = "localhost" Dim add As IPAddress = IPAddress.Parse("220.255.41.189") Public Shared Connected As New ManualResetEvent(False) #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub blisten_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles blisten.Click Listener = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Listener.Blocking = False Listener.Bind(New IPEndPoint(add, RemotePort)) Listener.Listen(1) ListBox1.Items.Add("Waiting for connection...") Listener.BeginAccept(New AsyncCallback(AddressOf AcceptConnection), Listener) End Sub Public Sub AcceptConnection(ByVal ar As IAsyncResult) ListBox1.Items.Add("Connection established.") Connected.Set() Dim serverSock As Socket = CType(ar.AsyncState, Socket) Dim clientSock As Socket = serverSock.EndAccept(ar) Dim buffer(1024) As Byte While True If (clientSock.Poll(100, SelectMode.SelectRead)) Then Dim count As Integer = clientSock.Receive(buffer) ListBox1.Items.Add(System.Text.Encoding.ASCII.GetString(buffer, 0, count)) End If End While End Sub Private Sub bsend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bsend.Click Dim Stream As NetworkStream = Client.GetStream() Dim dataSend As [Byte]() = System.Text.Encoding.ASCII.GetBytes(TextBox1.Text) 'Send Message Stream.Write(dataSend, 0, dataSend.Length) Stream.Flush() End Sub End Class my client source code: Imports System.Net Imports System.Net.Sockets Imports System.Threading Imports System.IO Imports System.Text Public Class Form1 Inherits System.Windows.Forms.Form Private Client As TcpClient Private Listener As Socket Private RemotePort As Integer = 1337 Private RemoteHost As String = "localhost" Dim add As IPAddress = IPAddress.Parse("220.255.41.189") Public Shared Connected As Ne

      M Offline
      M Offline
      Mohamed Ishak
      wrote on last edited by
      #2

      For sending messages and files over network you can see many articles and you can get refrences that is fully managed .so you can use in your project.if you are in neck. eample :unolibs.Net.dll its vey useful.search here in articls or googling it Ishak

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups