Click here to Skip to main content
15,921,905 members
Home / Discussions / Visual Basic
   

Visual Basic

 
Questionprinting RTB contents Pin
BooleanTrue13-Oct-07 11:50
professionalBooleanTrue13-Oct-07 11:50 
AnswerRe: printing RTB contents Pin
Dave Kreskowiak13-Oct-07 15:23
mveDave Kreskowiak13-Oct-07 15:23 
AnswerRe: printing RTB contents Pin
Duncan Edwards Jones14-Oct-07 0:44
professionalDuncan Edwards Jones14-Oct-07 0:44 
QuestionEditing Text Files and Creating new one of them Pin
Kalpeshpatelbyk13-Oct-07 2:07
Kalpeshpatelbyk13-Oct-07 2:07 
AnswerRe: Editing Text Files and Creating new one of them Pin
pmarfleet13-Oct-07 4:40
pmarfleet13-Oct-07 4:40 
AnswerRe: Editing Text Files and Creating new one of them Pin
Christian Graus13-Oct-07 10:29
protectorChristian Graus13-Oct-07 10:29 
QuestionTargetInvocationException, FileNotFoundException, assemblys, remoting, services, depression. Pin
redjen13-Oct-07 2:02
redjen13-Oct-07 2:02 
AnswerRe: TargetInvocationException, FileNotFoundException, assemblys, remoting, services, depression. Pin
redjen13-Oct-07 2:03
redjen13-Oct-07 2:03 
Code for Service:

Imports System.Runtime.Remoting
Imports MyServer
Imports SharedClasses

Public Class MyService

Private proxy As Server


Protected Overrides Sub OnStart(ByVal args() As String)

RemotingConfiguration.Configure("C:\chat\MyService\bin\Release\ServerForm.config", False)

proxy = CType(Activator.GetObject(Type.GetType("SharedClasses.IServer, SharedClasses"), "tcp://localhost:8085/yakkityYak"), SharedClasses.IServer)

Dim objEventLog As New EventLog()


objEventLog.Source = "MyService"
objEventLog.WriteEntry("proxy created")

'StartTimer()

' Add code here to start your service. This method should set things
' in motion so your service can do its work.
End Sub

Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub

End Class




Code for Server:

Imports SharedClasses

Public Class Server
Inherits MarshalByRefObject
Implements IServer

Private htMsgDel As New Hashtable
Private htUsrDel As New Hashtable

Public msgDel As IServer.msgCallBack
Public usrDel As IServer.usrCallBack


Public Function Connect(ByVal msgParcel As Parcel, ByVal usrParcel As Parcel, ByVal userName As String) As Boolean Implements IServer.Connect

SyncLock GetType(Server)

Dim connected As Boolean

If Not htUsrDel.ContainsKey(userName) Then

htMsgDel.Add(userName, msgParcel.msgDel())
htUsrDel.Add(userName, usrParcel.usrDel())
BroadcastUsers(userName)


connected = True
Else
MsgBox("The username " & userName & " is not available.")
End If

Return connected

End SyncLock

End Function


Public Sub disConnect(ByVal userName As String) Implements SharedClasses.IServer.disConnect

SyncLock GetType(Server)
htMsgDel.Remove(userName)
htUsrDel.Remove(userName)
BroadcastUsers(userName)

End SyncLock

End Sub


Public Sub BroadcastUsers(ByVal senderName As String) Implements IServer.BroadcastUsers

Dim alUsers As New ArrayList

For Each userName As String In htUsrDel.Keys
If Not userName = "server" Then
alUsers.Add(userName)
End If
Next

For Each userName As String In htUsrDel.Keys
If Not userName = senderName Then
usrDel = htUsrDel.Item(userName)
usrDel(alUsers)
End If
Next

End Sub


Public Sub Message(ByVal msg As String, ByVal userName As String) Implements IServer.Message

SyncLock GetType(Server)
For Each user As String In htMsgDel.Keys
If Not user = userName Then
msgDel = htMsgDel.Item(user)
msgDel(userName & ": " & msg & vbCrLf, userName)
End If
Next
End SyncLock

End Sub


Public Function getUsers() As ArrayList Implements IServer.getUsers

Dim alUsers As New ArrayList

For Each userName As String In htMsgDel.Keys
alUsers.Add(userName)
Next

Return alUsers

End Function


Public Sub TickMessage(ByVal msg As String) Implements IServer.TickMessage

SyncLock GetType(Server)
For Each user As String In htMsgDel.Keys
If Not user = "server" Then
msgDel = htMsgDel.Item(user)
msgDel(msg & vbCrLf, user)
End If


Next
End SyncLock

End Sub

End Class




Code for Server config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application>
<channels>
<channel ref="tcp" port="8085">
<serverProviders>
<provider ref="wsdl" />
<formatter ref="soap" typeFilterLevel="Full" />
<formatter ref="binary" typeFilterLevel="Full" />
</serverProviders>
<clientProviders>
<formatter ref="binary" />
</clientProviders>
</channel>
</channels>
<service>
<wellknown type="MyServer.Server, MyServer" objectUri="yakkityYak" mode="Singleton" />
</service>
<!-- <lifetime leaseTime="10S" sponsorshipTimeOut="10S" renewOnCallTime="5S"/> -->
</application>
</system.runtime.remoting>
</configuration>





Code for Client:

Imports System.Runtime.Remoting.Channels.ChannelServices
Imports System.Runtime.Remoting.Channels.TCP
Imports SharedClasses

Public Class ClientForm

Private IPAddress As String
Private userName As String
Private proxy As IServer

Public msgDel As IServer.msgCallBack
Public usrDel As IServer.usrCallBack

Private myConfiguration As Configuration

Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click

If txtUserName.Text = "" Then
MsgBox("enter a user name please")
txtUserName.Focus()
ElseIf Not txtUserName.Text.Length <= 13 Then
MsgBox("user name must be 13 characters or less")
txtUserName.Focus()
Else

Dim chan As TcpChannel

chan = New TcpChannel(0)
RegisterChannel(chan, False)

proxy = Activator.GetObject(Type.GetType("SharedClasses.IServer, SharedClasses"), "tcp://localhost:8085/yakkityYak")

' Send message delegate
msgDel = AddressOf msgCallBack
Dim msgParcel As Parcel = New Parcel(msgDel)
usrDel = AddressOf usrCallBack
Dim usrParcel As Parcel = New Parcel(usrDel)

userName = txtUserName.Text

Try
Dim connected As Boolean = proxy.Connect(msgParcel, usrParcel, userName)
If connected Then

btn.Enabled = False
btnSend.Enabled = True
txtUserName.Enabled = False
Me.Text = "Client : " & txtUserName.Text
ToolStripConnect.Text = "Connected"

For Each user As String In proxy.getUsers()
If Not user = "server" Then
lstUserNames.Items.Add(user)
End If
Next

End If

Catch ex As Exception
MsgBox(ex.ToString)
End Try




End If

End Sub


Private Sub ClientForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
If Not proxy Is Nothing Then
proxy.disConnect(userName)
End If
End Sub


Public Sub usrCallBack(ByVal userNames As ArrayList)
lstUserNames.Items.Clear()
For Each user As String In userNames
lstUserNames.Items.Add(user)
Next
End Sub


Public Sub msgCallBack(ByVal msg As String, ByVal userName As String)
rtbMessages.AppendText(msg)
End Sub


Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
If Not txtMessage.Text = "" Then
proxy.Message(txtMessage.Text, userName)
msgCallBack(userName & ": " & txtMessage.Text & vbCrLf, userName)
txtMessage.Text = ""
txtMessage.Focus()
End If

End Sub


Private Sub ClientForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnSend.Enabled = False
IPAddress = "localhost"
End Sub


Private Sub contextUser_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles contextUser.Opening
If Not lstUserNames.SelectedIndex = -1 Then
MsgBox(lstUserNames.SelectedItem.ToString)
End If
End Sub



Private Sub mnuConfiguration_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuConfiguration.Click
If myConfiguration Is Nothing Then
myConfiguration = New Configuration
End If
myConfiguration.Show()
End Sub




End Class




Code for serializable object

<Serializable()> Public Class Parcel

Private msgDelegate As IServer.msgCallBack
Private usrDelegate As IServer.usrCallBack


Public Sub New(ByVal del As IServer.msgCallBack)
msgDelegate = del
End Sub

Public Sub New(ByVal del As IServer.usrCallBack)
usrDelegate = del
End Sub

Public ReadOnly Property msgDel() As IServer.msgCallBack
Get
Return msgDelegate
End Get
End Property

Public ReadOnly Property usrDel() As IServer.usrCallBack
Get
Return usrDelegate
End Get
End Property

End Class




code for interface to server

Public Interface IServer

Delegate Sub msgCallBack(ByVal s As String, ByVal userName As String)
Delegate Sub usrCallBack(ByVal userNames As ArrayList)

Function Connect(ByVal msgDel As Parcel, ByVal usrDel As Parcel, ByVal userName As String) As Boolean
Sub disConnect(ByVal userName As String)
Sub Message(ByVal msg As String, ByVal userName As String)
Sub TickMessage(ByVal msg As String)
Sub BroadcastUsers(ByVal senderName As String)

Function getUsers() As ArrayList

End Interface





code for the server Gui ***** not used anymore, this is what the service is replacing... hopefully...

Imports System.Runtime.Remoting
Imports MyServer
Imports SharedClasses

Public Class ServerForm

Private proxy As New Server

Public msgDel As IServer.msgCallBack
Public usrDel As IServer.usrCallBack


Private Sub ServerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mnuShutdown.Enabled = False
Timer1.Enabled = True
End Sub


Private Sub StartServerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuStart.Click
'configure server
RemotingConfiguration.Configure("ServerForm.config", False)
proxy = CType(Activator.GetObject(Type.GetType("SharedClasses.IServer, SharedClasses"), "tcp://localhost:8085/yakkityYak"), IServer)

'setup delegates
msgDel = AddressOf MsgCallBack
Dim msgParcel As Parcel = New Parcel(msgDel)
usrDel = AddressOf usrCallBack
Dim usrParcel As Parcel = New Parcel(usrDel)
'connect to proxy
Dim connected As Boolean = proxy.Connect(msgParcel, usrParcel, "server")

mnuStart.Enabled = False
mnuShutdown.Enabled = True

toolStripConnect.Text = "Server Started"


End Sub


Public Sub MsgCallBack(ByVal msg As String, ByVal userName As String)
rtbMessages.AppendText(msg)
End Sub


Public Sub usrCallBack(ByVal userNames As ArrayList)
lstUserNames.Items.Clear()
For Each user As String In userNames
lstUserNames.Items.Add(user)
Next
End Sub


Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
proxy.TickMessage("sss")
MsgBox("x")

End Sub
End Class



thanks for your time Smile | :)
GeneralRe: TargetInvocationException, FileNotFoundException, assemblys, remoting, services, depression. Pin
redjen13-Oct-07 14:29
redjen13-Oct-07 14:29 
QuestionHow to assign case to the event handler ? Pin
liv2luv13-Oct-07 1:59
liv2luv13-Oct-07 1:59 
AnswerRe: How to assign case to the event handler ? Pin
Luc Pattyn13-Oct-07 3:09
sitebuilderLuc Pattyn13-Oct-07 3:09 
QuestionFile splitting Logic Pin
DON34512-Oct-07 23:53
DON34512-Oct-07 23:53 
AnswerRe: File splitting Logic Pin
Guffa13-Oct-07 0:53
Guffa13-Oct-07 0:53 
AnswerRe: File splitting Logic Pin
Luc Pattyn13-Oct-07 3:11
sitebuilderLuc Pattyn13-Oct-07 3:11 
QuestionProblem in Running EXE on Network when using ODBCConnection Object Pin
kkb_200112-Oct-07 21:12
kkb_200112-Oct-07 21:12 
AnswerRe: Problem in Running EXE on Network when using ODBCConnection Object Pin
Dave Kreskowiak13-Oct-07 3:52
mveDave Kreskowiak13-Oct-07 3:52 
QuestionHelp needed to Manipulate CSV Cell data..... Pin
paulk1112-Oct-07 12:26
paulk1112-Oct-07 12:26 
AnswerRe: Help needed to Manipulate CSV Cell data..... Pin
Dave Kreskowiak13-Oct-07 3:48
mveDave Kreskowiak13-Oct-07 3:48 
GeneralRe: Help needed to Manipulate CSV Cell data..... Pin
paulk1113-Oct-07 4:39
paulk1113-Oct-07 4:39 
GeneralRe: Help needed to Manipulate CSV Cell data..... Pin
Dave Kreskowiak13-Oct-07 5:00
mveDave Kreskowiak13-Oct-07 5:00 
GeneralRe: Help needed to Manipulate CSV Cell data..... Pin
paulk1113-Oct-07 6:01
paulk1113-Oct-07 6:01 
GeneralRe: Help needed to Manipulate CSV Cell data..... Pin
paulk1113-Oct-07 6:09
paulk1113-Oct-07 6:09 
GeneralRe: Help needed to Manipulate CSV Cell data..... Pin
Dave Kreskowiak13-Oct-07 9:11
mveDave Kreskowiak13-Oct-07 9:11 
QuestionBindingSource Pin
sabr4912-Oct-07 9:04
sabr4912-Oct-07 9:04 
AnswerRe: BindingSource Pin
pmarfleet12-Oct-07 10:11
pmarfleet12-Oct-07 10:11 

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.