lidds Posted July 26, 2005 Posted July 26, 2005 Can anyone point me in the right direction of how to send a message to another user / computer on network from vb.net. I only want to send a message to other users that are running my app. I will store user computer info within a database table i.e. computer name and / or IP address. I have seen examples of sending messages using the net send option, but to be honest I was looking for a way that could display a customised message window rather than the msgbox that net send displays. If someone could point me in the best way to acheive this, that would be great. Thanks Simon Quote
rot13 Posted July 26, 2005 Posted July 26, 2005 Can anyone point me in the right direction of how to send a message to another user / computer on network from vb.net. I only want to send a message to other users that are running my app. I will store user computer info within a database table i.e. computer name and / or IP address. I have seen examples of sending messages using the net send option, but to be honest I was looking for a way that could display a customised message window rather than the msgbox that net send displays. If someone could point me in the best way to acheive this, that would be great. Thanks Simon You have to make your app listen for a connection on a port, and when it recieves a connection, start listening incoming data, then see if that data is from the application you want to recieve messages from, then display it however you want from the application. then, the application that you send with will have to have a socket, and send data to a System.Net.Sockets.RemoteEndPoint which is basically an IP and port it's really not hard... but it is kinda tricky if you've never done it before Do you want to do it asynchronously (I dont know if i spelled that right) or not? I would say yes... i would do it async all the time... but that's just me... I can help you out more once I know the answer to that question. Quote
lidds Posted July 26, 2005 Author Posted July 26, 2005 I will be doing it asynchronously as you suggested, but to be honest I have never done anything with sockets before, so any help you could give me would be much appreshiated. Thanks in advance Simon Quote
rot13 Posted July 26, 2005 Posted July 26, 2005 I will be doing it asynchronously as you suggested, but to be honest I have never done anything with sockets before, so any help you could give me would be much appreshiated. Thanks in advance Simon Alright... I'll type out a lil "article" with some psuedo code... it'll look like vb.net.. but it might not be all right... just to give you the idea (this is for the server part) Create the three following classes: clsSocket, clsSocketCollection, and clsListener. In clsSocket you basically need something like the following (customize to w/e you need) 'this is what actually does the work... it's the socket... or it includes the socket Public Class clsSocket Dim MySocket As Socket Public ReadyOnly Property IP As Net.Sockets.IPAddress Get Return DirectCast(MySocket.RemoteEndPoint, Net.Sockets.IPAddress).Address End Get End Property Public Sub New(ByVal Socket As Net.Sockets.Socket) MySocket = Socket MySocket.BeginRecieve(blah blah blah, yuou can figure it out... lol) End Sub Public Sub CloseSocket() MySocket.CloseConnection 'w/e End Sub Public Sub Incoming(ByVal IAR as IAsyncResult) MySocket.EndRecieve(IAR) MySocket.BeginRecieve(blah blah blah, yuou can figure it out... lol) End Sub 'Theres more stuff... but I don't wanna type it all out... you'll have to read and figure it out like i did... lol End Class 'This is just a collection to hold,add, and remove clients Public Class clsSocketCollection Inherits System.CollectionBase Public Sub AddClient(ByVal Client As clsClient) MyBase.List.Add(Client) End Sub Public Sub RemoveClient(ByVal Client As clsClient) If MyBase.List.Contains(Client) Then MyBase.List.Remove(Client) End If End Sub Public Sub Remove(ByVal Index As Integer) If MyBase.List.Count >= Index then MyBase.List.Remove(MyBase.List(Index)) End If End Sub End Class Public Class clsListener Dim cSocketCollection As New clsSocketCollection Dim TCPListener As New TCPListener Public Sub StartListening() TCPListener.BeginListening(blah blah blah, you can figure all this out) End Sub Public Sub ConnectionAttempt(ByVal IAR As IAsyncResult) Dim cSocket as new clsSocket(TCPListener.EndListening(IAR)) TCPListener.StartListening(Same Stuff As IN StartListening) End Sub End Class This will give you an idea of some of the steps... but you still have to have a way to get the icoming data from the clients in the collection... youll have to use delegates... or i would anyways... and theres lots more left out... I'll add more later... Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.