# ASP.Net socket programming

**URL:** <https://boards.straightdope.com/t/asp-net-socket-programming/131564>\
**Category:** Factual Questions\
**Created:** [October 9, 2002, 5:08pm UTC](https://boards.straightdope.com/t/asp-net-socket-programming/131564 "2002-10-09T17:08:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohyneenm](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mohyneenm](https://boards.straightdope.com/u/mohyneenm)\
**Post date:** [October 9, 2002, 5:08pm UTC](https://boards.straightdope.com/t/asp-net-socket-programming/131564/1 "2002-10-09T17:08:04Z")

</div>

Hi, I am trying to implement the MSN messenger protocol in  
[ASP.Net](http://ASP.Net) but can’t get any response from the server. It’s  
returning an empty string. Can somebody point out what’s  
wrong with the following code:

* * *

Imports System.Text

Public Class WebForm1  
Inherits System.Web.UI.Page  
Protected WithEvents Button1 As  
System.Web.UI.WebControls.Button

#Region " Web Form Designer Generated Code "

```
'This call is required by the Web Form Designer.
&lt;System.Diagnostics.DebuggerStepThrough()&gt; Private Sub 

```

InitializeComponent()

```
End Sub

Private Sub Page_Init(ByVal sender As System.Object, 

```

ByVal e As System.EventArgs) Handles MyBase.Init  
'CODEGEN: This method call is required by the Web  
Form Designer  
'Do not modify it using the code editor.  
InitializeComponent()  
End Sub

#End Region

```
Protected WithEvents Button2 As 

```

System.Web.UI.WebControls.Button  
Dim trialID As Integer  
Dim networkStream As System.Net.Sockets.NetworkStream  
Dim tcpClient As New System.Net.Sockets.TcpClient()

```
Private Sub Page_Load(ByVal sender As System.Object, 

```

ByVal e As System.EventArgs) Handles MyBase.Load  
tcpClient.Connect(“64.4.13.58”, 1863)  
trialID = 0  
networkStream = tcpClient.GetStream()  
End Sub

```
Private Sub Button1_Click(ByVal sender As 

```

System.Object, ByVal e As System.EventArgs) Handles  
Button1.Click  
If networkStream.CanWrite Then  
Dim sendBytes As Byte =  
Encoding.ASCII.GetBytes(“VER 0 MSNP7 MSNP6 MSNP5 MSNP4  
CVRO” & vbCrLf)  
Response.Write(Encoding.ASCII.GetString  
(sendBytes))  
networkStream.Write(sendBytes, 0, 32)  
End If  
End Sub

```
Private Sub Button2_Click(ByVal sender As 

```

System.Object, ByVal e As System.EventArgs) Handles  
Button2.Click  
If networkStream.DataAvailable Then  
Dim bytes(tcpClient.ReceiveBufferSize) As Byte  
networkStream.Read(bytes, 0, CInt  
(tcpClient.ReceiveBufferSize))

```
        Dim returndata As String = 

```

Encoding.ASCII.GetString(bytes)  
Response.Write(returndata)  
Else  
If Not networkStream.CanRead Then  
Response.Write(“You can not write data to  
this stream”)  
tcpClient.Close()

```
        End If
    End If
End Sub

```

End Class

* * *
