December 20th, 1999, 06:56 PM
Can anyone show me any code that will send a message to a specific machine on a network?
Thanks very much in advance,
Bill
Thanks very much in advance,
Bill
|
Click to See Complete Forum and Search --> : Winsock December 20th, 1999, 06:56 PM Can anyone show me any code that will send a message to a specific machine on a network? Thanks very much in advance, Bill AndyK December 21st, 1999, 01:03 PM The easiest way is to use MSWINSCK.ocx (p.s. sorry for being confused about your email) Ok the basics of sending a message over two computers is this: 1) You have to connect to person's IP with identical port, so if his Remote Port will be "100" then your Local Port will have to be "100" too. OK follow this steps and you should be fine: 1) Start new project 2) Add to it MSWINSCK.ocx (Microsoft winsock control)....to add it (default name should be winsock1, if not change it to winsock1) use Ctrl+t if you don't know how :) 3) Add 5 textboxes (name them: txtRemIP,txtRemPort,txtLocalPort,MSGSEND, arrival) 4) Add 2 command buttons (name it: connect and send) 5) Ok now paste this strait into the form: option Explicit private Sub connect_Click() With Winsock1 .RemoteHost = Trim(txtRemIP) .RemotePort = Trim(txtRemPort) If .LocalPort = empty then .LocalPort = Trim(txtLocalPort) .Bind .LocalPort End If End With End Sub private Sub Form_Load() Winsock1.Protocol = sckUDPProtocol txtRemIP = Winsock1.LocalIP txtRemPort = "7" txtLocalPort = "8" MSGSEND = "Hello" arrival = "Goodbye" connect.Caption = "Connect" send.Caption = "Send" End Sub private Sub MSGSEND_KeyPress(KeyAscii as Integer) Dim NewL as string If KeyAscii = 13 then NewL = MSGSEND Winsock1.SendData NewL End If End Sub private Sub send_Click() Dim NewL as string NewL = MSGSEND Winsock1.SendData NewL End Sub private Sub Winsock1_DataArrival(byval bytesTotal as Long) Dim arrived as string Winsock1.GetData arrived arrival.Text = arrived End Sub Ok now to test it first follow carefully what's above then compile it to an exe....now run the project from VB and run exe file that you have just compiled from code above...now you should have two windows in front of you. Make sure that local port and remote port aren't the same and that one one window LOCAL port is the same as REMOTE port on other form...this is vital or it won't work. Ok after all ports had been set and you have pressed "Connect" on both windows... click send on one window and watch what happens on the other window...WOW :).... ANy problems or if you need an explanations for this code...contact me..... codeguru.com
Copyright Internet.com Inc., All Rights Reserved. |