Results 1 to 11 of 11

Thread: Send messages with the winsock control

  1. #1

    Thread Starter
    Addicted Member Jakys's Avatar
    Join Date
    Dec 1999
    Location
    Norway
    Posts
    180

    Post

    I'd like to send messages over a network(LAN) with the winsock control, but i can't figure out how to do that. If any of you have som samples, or can help with code, it would be great.

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Posts
    232

    Post

    I use NT and the NET SEND command:

    For sample:

    Target$ = username
    OR
    Target$ = computername
    Message$ = "This server will shut down in 5 minutes."
    Shell ("net send " & Target & " " & Message)

    You can send a message only to a name that is active on the network. If the message is sent to a username, that user must be logged on and running the Messenger service to receive the message.
    Look help about NET SEND.

    ------------------
    smalig
    [email protected]
    http://vbcode.webhostme.com/


  3. #3

    Thread Starter
    Addicted Member Jakys's Avatar
    Join Date
    Dec 1999
    Location
    Norway
    Posts
    180

    Post

    I got Windows 98 Service Pack 2, do I have the NetSend command here?

  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    There is a file NET.EXE and SEND is one of it's parameters. You can also use the NetMessageBufferSend API of NetAPI32 library, I don't have the code handy though....

  5. #5
    Addicted Member
    Join Date
    Oct 1999
    Posts
    232

    Post

    OK, here is a code with NetMessageBufferSend function: http://vbcode.webhostme.com/en/click.asp?id=115

    Best Regards.

    ------------------
    smalig
    [email protected]
    http://vbcode.webhostme.com/


  6. #6
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Thank you Smalig. Your site is great, keep it up!

  7. #7
    Addicted Member
    Join Date
    Jan 1999
    Posts
    173

    Post

    You could even try downloading my DLL which allows two computers to connect and send pictures, text, files and binary over a winsock connection: http://www.vbsquare.com/internet/

    ------------------
    "To the glory of God!"


  8. #8
    Guest

    Post

    NET SEND is fine and dandy, if you have it. The problem is, how do you know that your end user has it? You'd have to write a detection function. And are you allowed to distribute it? I doubt it. So what are you to do? It's simple. Write a small chat client.

    you'll need a form with two text boxes, two command buttons and a winsock control.

    Sub Form_Load()
    Namer = InputBox("Enter Username for this session:", "Username", "User")
    'Set the port to listen on
    winsock1.LocalPort = 1002
    'Begin listening
    winsock1.Listen
    End Sub

    Sub Form_Resize()
    Text1.Width = Me.ScaleWidth
    Text2.Width = Me.ScaleWidth
    Text1.Height = Me.ScaleHeight - text2.Height
    Text2.Top = Text1.Height
    End Sub

    Sub Command1_Click()
    Dim strRemoteHost As String
    'Get the name of a computer to connect to
    strRemoteHost = InputBox("Enter name or IP address of computer " & _
    "to connect to.", vbOKCancel)
    'Exit if cancelled
    If strRemoteHost = "" Then Exit Sub
    'Close any open connections
    winsock1.Close
    'Set the name of the computer to connect to
    winsock1.RemoteHost = strRemoteHost
    'Specify a port number on remote host
    winsock1.RemotePort = 1002
    'This seems to prevent some TCP errors
    DoEvents
    'Request the connection
    winsock1.Connect
    End Sub

    Sub Command2_Click
    winsock1.Close
    DoEvents
    winsock1.Listen
    End Sub

    Sub winsock1_Close()
    'When connection by remote machine, go back to listening
    winsock1.Close
    winsock1.Listen
    End Sub

    Sub winsock1_ConnectionRequest(ByVal requestID As Long)
    winsock1.Close
    winsock1.Accept requestID
    End Sub

    Sub winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim strText As String
    'Get data
    winsock1.GetData strText
    'Display data received
    Text1 = Text1 & Chr(13) & Chr(10) & strText & vbCrLf
    'Move cursor to end
    Text1.SelStart = Len(Text1)
    End Sub

    Sub Text2_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
    Case Is = 13
    sendMessage ("" & Text2.Text)
    txtMsg.Text = ""
    End Select

    End Sub

    Sub sendMessage(Msg As String)
    Static strSend As String
    'Make sure there is a connection
    If winsock1.State <> sckConnected Then Exit Sub
    'Send the string
    winsock1.SendData Namer & ": " & Msg
    Text1.Text = Text1.Text & Chr(13) & Chr(10) & Namer & ": " & Msg
    'Clear the variable
    strSend = ""
    'Keep track of what is being typed
    strSend = strSend & Msg
    End Sub

    and in the globals section:
    Option Explicit
    Dim Namer as String

  9. #9
    New Member
    Join Date
    Oct 1999
    Location
    St. Louis, MO. USA
    Posts
    4

    Post

    To use the NetMessageBufferSend API call you must be running Windows NT on the host. The recipient can be on Windows NT or Windows 95/98(as long as Winpopup is running).

    In response to Rippleman, NetApi32.dll is on every Windows NT 4.0 system.

  10. #10
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    Rippleman

    the problem with a chat client is that the user has to have the app installed an running. If you were to use NetMessageBufferSend over a LAN, the only thing the recipient has to have running is the Messenger Service (which by default is running)

  11. #11
    Guest

    Post

    ok, i guess that would work then. I'd never heard of that particular API, which is why i figured it was a special dll. In response to everyone, I think that this method would still work, but the NET SEND would work also, so i guess its how much you want to code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width