Click here to Skip to main content
16,005,389 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralCorrupt Text Files Pin
Barry Etter21-Jan-04 13:11
Barry Etter21-Jan-04 13:11 
GeneralRe: Corrupt Text Files Pin
Mike Ellison21-Jan-04 14:39
Mike Ellison21-Jan-04 14:39 
GeneralRe: Corrupt Text Files Pin
Dave Kreskowiak22-Jan-04 1:02
mveDave Kreskowiak22-Jan-04 1:02 
Generallistview + selecteditem Pin
Anonymous21-Jan-04 11:17
Anonymous21-Jan-04 11:17 
GeneralRe: listview + selecteditem Pin
Dave Kreskowiak22-Jan-04 0:57
mveDave Kreskowiak22-Jan-04 0:57 
GeneralLooking for IT Professionals on H1B Visa Transfer/Faster GreenCard Processing Pin
Keith_00221-Jan-04 10:42
Keith_00221-Jan-04 10:42 
GeneralRe: Looking for IT Professionals on H1B Visa Transfer/Faster GreenCard Processing Pin
keshavcode21-Jan-04 14:59
keshavcode21-Jan-04 14:59 
GeneralFirewall HELP Pin
zoodayz21-Jan-04 9:33
zoodayz21-Jan-04 9:33 
Ok this is my first post here. So Im admitting im a new bee ok How would I allow my app to run behind a Firewall and NAT????
I am not able to turn it off and I fell others sould not have to also or port forward but lets say with a code like this as a example I got from here
Also how about set it up to use random port would that have to do with.. Private Shared port As Integer = 44 ????

Thank you for any help ZoodayZ...


Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text

Public Class StateObject
Public workSocket As Socket = Nothing
Public BufferSize As Integer = 32767
Public buffer(32767) As Byte
Public sb As New StringBuilder()
End Class

Public Class SocketsClient
Public Event onConnect()
Public Event onError(ByVal Description As String)
Public Event onDataArrival(ByVal Data As Byte(), ByVal TotalBytes As Integer)
Public Event onDisconnect()
Public Event onSendComplete(ByVal DataSize As Integer)

Private Shared response As [String] = [String].Empty
Private Shared port As Integer = 44
Private Shared ipHostInfo As IPHostEntry = Dns.Resolve("localhost")
Private Shared ipAddress As ipAddress = ipHostInfo.AddressList(0)
Private Shared client As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

Public Sub Connect(ByVal RemoteHostName As String, ByVal RemotePort As Integer)
Try
client = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
port = RemotePort
ipHostInfo = Dns.Resolve(RemoteHostName)
ipAddress = ipHostInfo.AddressList(0)
Dim remoteEP As New IPEndPoint(ipAddress, port)
client.BeginConnect(remoteEP, AddressOf sockConnected, client)
Catch
RaiseEvent onError(Err.Description)
Exit Sub
End Try
End Sub

Public Sub SendData(ByVal Data() As Byte)
Try
Dim byteData As Byte() = Data
client.BeginSend(byteData, 0, byteData.Length, 0, AddressOf sockSendEnd, client)
Catch
RaiseEvent onError(Err.Description)
Exit Sub
End Try
End Sub

Public Sub Disconnect()
Try
client.Shutdown(SocketShutdown.Both)
Catch
End Try
client.Close()
End Sub

Public Function StringToBytes(ByVal Data As String) As Byte()
StringToBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(Data)
End Function

Public Function BytestoString(ByVal Data As Byte()) As String
BytestoString = System.Text.ASCIIEncoding.ASCII.GetString(Data)
End Function

Private Sub sockConnected(ByVal ar As IAsyncResult)
Try
If client.Connected = False Then RaiseEvent onError("Connection refused.") : Exit Sub
Dim state As New StateObject()
state.workSocket = client
client.BeginReceive(state.buffer, 0, state.BufferSize, 0, AddressOf sockDataArrival, state)
RaiseEvent onConnect()
Catch
RaiseEvent onError(Err.Description)
Exit Sub
End Try
End Sub

Private Sub sockDataArrival(ByVal ar As IAsyncResult)
Dim state As StateObject = CType(ar.AsyncState, StateObject)
Dim client As Socket = state.workSocket
Dim bytesRead As Integer

Try
bytesRead = client.EndReceive(ar)
Catch
Exit Sub
End Try

Try
Dim Data() As Byte = state.buffer
If bytesRead = 0 Then
client.Shutdown(SocketShutdown.Both)
client.Close()
RaiseEvent onDisconnect()
Exit Sub
End If
ReDim state.buffer(32767)

client.BeginReceive(state.buffer, 0, state.BufferSize, 0, AddressOf sockDataArrival, state)
RaiseEvent onDataArrival(Data, bytesRead)
Catch
RaiseEvent onError(Err.Description)
Exit Sub
End Try
End Sub

Private Sub sockSendEnd(ByVal ar As IAsyncResult)
Try
Dim client As Socket = CType(ar.AsyncState, Socket)
Dim bytesSent As Integer = client.EndSend(ar)
RaiseEvent onSendComplete(bytesSent)
Catch
RaiseEvent onError(Err.Description)
Exit Sub
End Try
End Sub

Public Function Connected() As Boolean
Try
Return client.Connected
Catch
RaiseEvent onError(Err.Description)
Exit Function
End Try
End Function
End Class

GeneralRe: Firewall HELP Pin
Dave Kreskowiak22-Jan-04 0:50
mveDave Kreskowiak22-Jan-04 0:50 
GeneralExit Code From VB application Pin
ANORTON21-Jan-04 5:27
ANORTON21-Jan-04 5:27 
GeneralRe: Exit Code From VB application Pin
Dave Kreskowiak21-Jan-04 6:20
mveDave Kreskowiak21-Jan-04 6:20 
GeneralRe: Exit Code From VB application Pin
ANORTON21-Jan-04 7:51
ANORTON21-Jan-04 7:51 
Generalclient server Pin
noureddine01010121-Jan-04 5:08
noureddine01010121-Jan-04 5:08 
GeneralRe: client server Pin
Mike Ellison21-Jan-04 15:02
Mike Ellison21-Jan-04 15:02 
QuestionHow to select an Item in a Listview Pin
code_gopher21-Jan-04 4:52
code_gopher21-Jan-04 4:52 
AnswerRe: How to select an Item in a Listview Pin
Mike Ellison21-Jan-04 14:54
Mike Ellison21-Jan-04 14:54 
Generalconnecting to access project Pin
Member 83296121-Jan-04 4:47
Member 83296121-Jan-04 4:47 
GeneralRe: connecting to access project Pin
code_gopher21-Jan-04 4:55
code_gopher21-Jan-04 4:55 
GeneralRe: connecting to access project Pin
Member 83296121-Jan-04 5:33
Member 83296121-Jan-04 5:33 
Generalvss automation with VB/VBA Pin
leonard2621-Jan-04 4:14
leonard2621-Jan-04 4:14 
GeneralMulti-Page Web Form Pin
rjcarney21-Jan-04 1:58
rjcarney21-Jan-04 1:58 
GeneralDrag And Drop Pin
NightCreature20-Jan-04 23:59
NightCreature20-Jan-04 23:59 
GeneralIExplorer Bar Pin
landsmann20-Jan-04 23:58
landsmann20-Jan-04 23:58 
GeneralIIS Configuration to set account Pin
Shenthil20-Jan-04 23:29
Shenthil20-Jan-04 23:29 
GeneralRe: IIS Configuration to set account Pin
Dave Kreskowiak21-Jan-04 6:30
mveDave Kreskowiak21-Jan-04 6:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.