|
-
Dec 16th, 1999, 05:15 PM
#1
Thread Starter
Addicted Member
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.
-
Dec 16th, 1999, 05:41 PM
#2
Addicted Member
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/
-
Dec 17th, 1999, 05:38 AM
#3
Thread Starter
Addicted Member
I got Windows 98 Service Pack 2, do I have the NetSend command here?
-
Dec 18th, 1999, 01:10 PM
#4
Guru
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....
-
Dec 18th, 1999, 10:20 PM
#5
Addicted Member
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/
-
Dec 19th, 1999, 01:05 AM
#6
Guru
Thank you Smalig. Your site is great, keep it up!
-
Dec 20th, 1999, 04:48 AM
#7
Addicted Member
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!"
-
Dec 20th, 1999, 06:17 AM
#8
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
-
Dec 21st, 1999, 06:56 AM
#9
New Member
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.
-
Dec 22nd, 1999, 12:46 PM
#10
Guru
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)
-
Dec 23rd, 1999, 08:34 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|