Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

for several days I can't figure out how to make a new connection after I

disposed it.

 

So I want to connect, disconnect, connect etc.....

What am I missing here?

 

This is what I have

 

Public mysocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

Public theend As Boolean

Public server As String = "news.ultrafeed.com"

Public serverport As Long = 119

Public ipsolve As IPHostEntry = Dns.Resolve(server)

Public ipend As New IPEndPoint(ipsolve.AddressList(0), serverport)

Public bb(1024) As Byte

 

 

Public Sub login()

If mysocket.Connected = True Then

MsgBox("Allready connected")

Exit Sub

Else

Dim server As String = "news.ultrafeed.com"

Dim serverport As Long = 119

Dim ipsolve As IPHostEntry = Dns.Resolve(server)

Dim ipend As New IPEndPoint(ipsolve.AddressList(0), serverport)

Dim mysocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

End If

 

Dim msg1 As Byte() = Encoding.ASCII.GetBytes("AUTHINFO user xxxx" & vbCrLf)

Dim msg2 As Byte() = Encoding.ASCII.GetBytes("AUTHINFO pass xxxx" & vbCrLf)

mysocket.Connect(ipend)

bb.Clear(bb, 0, 1024)

bytes = mysocket.Receive(bb, bb.Length, 0)

txtinfo.Text = Encoding.ASCII.GetString(bb)

loginfo.Text = Encoding.ASCII.GetString(bb)

mysocket.Send(msg1, 0, msg1.Length, 0)

bb.Clear(bb, 0, 1024)

bytes = mysocket.Receive(bb, bb.Length, 0)

txtinfo.Text = Encoding.ASCII.GetString(bb)

loginfo.Text = Encoding.ASCII.GetString(bb)

mysocket.Send(msg2, 0, msg2.Length, 0)

bb.Clear(bb, 0, 1024)

bytes = mysocket.Receive(bb, bb.Length, 0)

txtinfo.Text = txtinfo.Text + Encoding.ASCII.GetString(bb)

loginfo.Text = loginfo.Text + Encoding.ASCII.GetString(bb)

End Sub

 

 

Private Sub Disconnect()

Dim msg2 As Byte() = Encoding.ASCII.GetBytes("QUIT" & vbCrLf)

bb.Clear(bb, 0, 1024)

mysocket.Send(msg2, 0, msg2.Length, 0)

bytes = mysocket.Receive(bb, bb.Length, 0)

txtinfo.Text = txtinfo.Text + Encoding.ASCII.GetString(bb)

mysocket.Shutdown(SocketShutdown.Both)

mysocket.Close()

End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...