|
How do i convert the following into a fully multithreaded tcp server and remove the two addhandler(linerecieved,ondisconnected), i just know how
to remove the addhandler and make it into a separate thread.
any help would be appreciated.
thanks
jim
[UI form]
Option Strict On
Imports System.Threading
Imports System.Net.Sockets
Imports System.Net
Private myThread as thread
private mysocket as Tcplistener
Private Sub clsServer_load(...)
mythread = New threading.thread(addressof Dolisten)
mythread.start()
end sub
Pirvate dolisten()
dim localaddr = system.net.ipaddress
try
mysocket = new Tcplistener(localaddr,1234)
mysocket.start()
do
dim x as New clsClient(mysocket.AcceptTcpClient)
AddHandler x.Disconnected, AddressOf onDisconnected
AddHandler x.myReceived, AddressOf LineReceived
mcolClients.Add(x.ID, x)
Loop Until False
catch
end try
end sub
Public Sub LineReceived(ByVal sender As clsClient, ByVal strString As String)
'process recive data here
end sub
[clsClient.vb]
Option Strict On
Imports System.Net.Sockets
Imports System.Text
'client class to handle the new client connected to the server
Public Class clsClient
Public Event Disconnected(ByVal sender As clsClient)
Public Event LineReceived(ByVal sender As clsClient, ByVal Data As String)
Private mgID As Guid = Guid.NewGuid
Const BUFFER_SIZE As Integer = 512
Private mobjClient As TcpClient
Private marData(BUFFER_SIZE) As Byte
Private mobjText As New StringBuilder()
Public ReadOnly Property ID() As String
Get
Return mgID.ToString
End Get
End Property
Public Sub New(ByVal client As TcpClient)
mobjClient = client
mobjClient.GetStream.BeginRead(marData, 0, BUFFER_SIZE, AddressOf DoStreamReceive, Nothing)
End Sub
Private Sub DoStreamReceive(ByVal ar As IAsyncResult)
Dim intCount As Integer
Dim clientdata As String = Encoding.ASCII.GetString(marData)
Try
SyncLock mobjClient.GetStream
intCount = mobjClient.GetStream.EndRead(ar)
End SyncLock
If intCount < 1 Then
RaiseEvent Disconnected(Me)
Exit Sub
End If
RaiseEvent LineReceived(Me, clientdata)
SyncLock mobjClient.GetStream
mobjClient.GetStream.BeginRead(marData, 0, BUFFER_SIZE, AddressOf DoStreamReceive, Nothing)
End SyncLock
Catch ex As Exception
RaiseEvent Disconnected(Me)
End Try
End Sub
Public Sub Send(ByVal Data As String)
SyncLock mobjClient.GetStream
Dim w As New IO.StreamWriter(mobjClient.GetStream)
w.Write(Data)
w.Flush()
End SyncLock
End Sub
End Class
-just make it tough
|
|
|
|
|
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=331&lngWId=10
Multi-Threaded TCP Chat Example
This is an example of how to implement the System.Sockets and System.Threading classes in VB.Net. It includes a multi-threaded server application as well as a client to demomstrate its use. This code is based off of a code example written in C# by Nick Ruisi on PSC, so give credit where credit is due. Enjoy!
|
|
|
|
|
im not saying that its mine, that is why im needing your help, who knows that code also was taken from other authors too aside from the author who posted on PSC
so i would give credit to those who made the .NET Team, not just the author who posted it on PSC
do you think if i made that code i would still be asking you?
peace!
jim
-just make it tough
|
|
|
|
|
jimmypearly,
Hey jim, that quote was just pasted in from the page link I sent you, It's on that page as a description. I didn't write it.
I don't think it was intended to be offensive, especialy by me.
Sorry.
|
|
|
|
|
I need to write a macro app. This is why I need to know how can I immitate clicking somewhere in the window of other app. Thanks for answers.
|
|
|
|
|
|
For example: There's an foreign app, in its form is a button or other control... I want to build an app, which allowes me to generate the click programmaticaly, without using a mouse.
|
|
|
|
|
You could generate the mouse click, but how are you going to guarantee that the window your "clicking" on is going to be in the exact same place every time it comes up?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
It's maximized window all the time. But how can I do it?
|
|
|
|
|
I gave you a hint at what the pitfalls are...
But, it's not as easy as it would sound. You have to define the structures that define the type and specifics of the input your sending, namely mouse clicks, and use the SendInput Win32 API function to post the message for you.
See SendInput on P/Invoke.net[^] for an example and some docs. Make SURE you follow and read the links for defining the INPUT, MOUSEINPUT, KEYBOARDINPUT, HARDWAREINPUT, and VK structures!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks a lot. I will look at it and I will try it tommorow. So please, look back at this thread tommorow this time, I will let you know how I solved it. Now I go to bed It's about midnight.
|
|
|
|
|
You can use these api functions to simulate a button click
Declare these at the top of your class/ form/ module
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const BM_CLICK = &HF5
I used another command button to click ok on a message box.
If you investigtate the findwindow function, the second param can be the name of the window to find (at present it is the Msgbox class id but you can place vbnullstring there and place the window name in the place of vbnullstring)
Private Sub Command1_Click()
Dim x As Long, staticx As Long, MyStr As String, y As String, control As Long
'Find the window you specify
x = FindWindow("#32770", vbNullString)
' get handle to Ok button
control = FindWindowEx(x, 0, "Button", "Ok")
' click the button
SendMessage control, BM_CLICK, 0, 0
SendMessage control, BM_CLICK, 0, 0
End Sub
For some reason you need to send the message twice. I think it is because the first just selects it.
Enjoy
"I am what i am, and i do what i do, but sometimes i do, what you want me to do."
|
|
|
|
|
I am afraid this code doesn't work for me ( What's your operating system -I have WXPP, VS.NET.
|
|
|
|
|
I've just found out why it doesn't work - MSDN - This function was superseeded for WXP and W2k
|
|
|
|
|
The reason is possibly because this is vb6 code.
I have Windows XP and it works fine, did you want it for vb.net then?
Sorry mate
|
|
|
|
|
I want to do the way Favorite of IE, while high light on a favorite, you can
right click to rename or delete a favorite menuitem. Expert, how can I do
this, thank you!
|
|
|
|
|
Do what? Create your own context menu? Add an item to IE's context menu? Add an item to the shell context menu?
All you did was describe right-clicking on an item in IE's Favorites menu and renaming it. You haven't said anything about what you want to do.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
sorry for poor description, I'm working on an application that also have favorite toolbar like IE, but then I don't know how to do a popup context menu when click on one of the favorite menu item. Can you help?
|
|
|
|
|
OK. You can start by reading Introduction to the Windows Forms ContextMenu Component[^] on MSDN. There's alot to read, so it'll probably take you a day to through it and try some examples before you completely understand how they work.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I do know how to use context menu but it does not working for this case, it's does not usable for MainMenu, since there is no ContextMenu option
|
|
|
|
|
Since you want a popup menu (Context menu) to come up when you right-click an item, the MainMenu has nothing to do with it. You're creating a ContextMenu and assigning it to the control that you want the menu to pop up for when you right-click that control. Go to that control's properties and look for the ContextMenu property. This is how your going to assign the menu you build to the control you want it to pop up on.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Internet explorer's Favorite Menubar(MainMenu), you can add,edit, or delete upon right click(ContextMenu show up) on the item you want to perform the action. I want to do something like that
|
|
|
|
|
Is there a way to do this? It would be nice to give a visual aid to the user to see which item when looking back to the list at a later time.
Right now it hihghligts upon clicking on an item in the list, but then looses the highlights.
Thanks for the help.
|
|
|
|
|
Set the HideSelection property to false to leave the selected item highlighted when the control loses focus.
Charlie
if(!curlies){ return; }
|
|
|
|
|
That's it, thanks. Sorry for the dumass question, I won't do it again for a couple days.
|
|
|
|
|