Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket
Help with sending and reciveing with a socket Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
Go Back  Xtreme Visual Basic Talk > > > Help with sending and reciveing with a socket


Reply
 
Thread Tools Display Modes
  #1  
Old 07-31-2007, 11:50 AM
3321thec 3321thec is offline
Freshman
 
Join Date: Apr 2007
Posts: 34
Default Help with sending and reciveing with a socket


Hello,

I tried to write an application that, when button1 is clicked, sends the content of a textbox to a port on 127.0.0.1(localhost). It should then receive a response from the listening object in my app, but it does not.

Here is my code:
Code:
Public Class Form1
    Dim rs As New Net.Sockets.TcpListener(Net.IPAddress.Parse("127.0.0.1"), 8119)
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Senddat()
    End Sub
    Sub Senddat()
        Dim ipadd As Net.IPAddress = Net.IPAddress.Parse("127.0.0.1")
        Dim endpoint As New System.Net.IPEndPoint(ipadd, 8119)
        Dim s As New Net.Sockets.Socket(endpoint.AddressFamily, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
        Dim ascii As New System.Text.ASCIIEncoding
        Dim bytesSent As [Byte]() = ascii.GetBytes(TextBox2.Text)
        Dim bytesrec(1024) As Byte
        Try
            s.Connect(endpoint)
            s.Send(bytesSent)
        Catch
            MsgBox("No Connect")
        End Try
        s.Receive(bytesrec)
        TextBox1.Text = ascii.GetString(bytesrec)
        s.Close()
    End Sub
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        rs.Start()
    End Sub
    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If rs.Pending = True Then
            Dim s As Net.Sockets.Socket = rs.AcceptSocket()
            Dim bytes(1024) As Byte
            Dim ascii As New System.Text.ASCIIEncoding
            Dim msg As String
            s.Receive(bytes)
            msg = ascii.GetString(bytes)
            If Not msg = "Name" Then
                msg = "John Colan"
            End If
            s.Send(ascii.GetBytes(msg))
        End If
    End Sub
End Class
Any help is greatly appreciated!

~3321Thec
Reply With Quote
  #2  
Old 08-11-2007, 06:58 PM
MKoslof's Avatar
MKoslofHelp with sending and reciveing with a socket MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Are you going through TCP/IP? If so, it would seem that you would create a New TcpListener object and a New TcpClient object and then write out the object.GetStream() via a StreamWriter or binary writing source in your button click event.

Then in your timer event which should be receiving, if Pending = true, you assign the TcpClient object = TcpListener object.AcceptTcpClient(). Then using a streamReader for example, read the object GetStream method, and while peek > -1 get the message, etc.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
Help with sending and reciveing with a socket Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
 
Help with sending and reciveing with a socket
Help with sending and reciveing with a socket
 
-->