|
-
Feb 8th, 2006, 08:26 PM
#1
Thread Starter
Addicted Member
Need some help
I have set up a small program which is basically the tutorial with some things changed so i can move an image around and have it shown on the other form. I can work it fine if its on the same computer but thats it, i cannot get it on another computer in or out of my network.
this is my code for the listening form
---------------------------------------------------------------
Option Explicit
Private Sub cmdSend_Click()
' send data from the textbox
txtchat.Text = "Waiter " & txtchat.Text
Winsock.SendData txtchat.Text
DoEvents
' display the text, and clear the textbox
txtmain.Text = txtmain.Text & vbCrLf & txtchat.Text
txtchat.Text = ""
End Sub
Private Sub Form_Load()
' set up the socket to listen on port 10101
Winsock.LocalPort = 10101
Winsock.Listen
End Sub
Private Sub Winsock_ConnectionRequest(ByVal RequestID As Long)
' reset the socket, and accept the new connection
Winsock.Close
Winsock.Accept RequestID
End Sub
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
' get the data and display it in the textbox
Winsock.GetData strData
txtmain.Text = ""
txtmain.Text = txtmain.Text & strData
txtmain.SelStart = Len(txtmain.Text)
Image2.Left = txtmain.Text
End Sub
-----------------------------------------------------
and my other form
--------------------------------------------------------
Option Explicit
Dim saLia As Integer
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyRight Then
Image1.Left = Image1.Left + 100
End If
End Sub
Private Sub Form_Load()
' set up the winsock to connect to the local computer
Winsock.RemoteHost = "127.0.0.1"
Winsock.RemotePort = 10101
Winsock.Connect
saLia = 1
End Sub
Private Sub cmdSend_Click()
' send the data thats in the text box and
' clear it to prepare for the next chat message
txtchat.Text = "Connecter " & txtchat.Text
Winsock.SendData txtchat.Text
DoEvents
txtmain.Text = txtmain.Text & vbCrLf & txtchat.Text
txtchat.Text = ""
End Sub
Private Sub Timer1_Timer()
txtchat.Text = Image1.Left
Winsock.SendData txtchat.Text
DoEvents
txtmain.Text = txtmain.Text & vbCrLf & txtchat.Text
txtchat.Text = ""
End Sub
Private Sub Winsock_Connect()
' we are connected!
MsgBox "Connected"
End Sub
Private Sub Winsock_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
' get the data from the socket
Winsock.GetData strData
' display it in the textbox
txtmain.Text = txtmain.Text & vbCrLf & strData
' scroll the box down
txtmain.SelStart = Len(txtmain.Text)
End Sub
Private Sub Winsock_Error(ByVal Number As Integer, Description As String, _
ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, _
ByVal HelpContext As Long, CancelDisplay As Boolean)
' an error has occured somewhere, so let the user know
MsgBox "Error: " & Description
' close the socket, ready to go again
End Sub
----------------------------------------------------------------
Please help me,, i've been trying to do this for a while now.
-
Feb 9th, 2006, 08:49 AM
#2
New Member
Re: Need some help
I don't know if i get it right but in the second form in the load event you seem to connect to the local host..This means that if someone tries to connect with you with the second form, he will only connect to his pc...Correct me if i am wrong.If i am right to correct this you could have a textbox where the user would enter the ip and the in the second form use
VB Code:
Winsock.RemoteHost = txtIp.Text
Winsock.RemotePort = 10101
Winsock.Connect
-
Feb 9th, 2006, 02:52 PM
#3
Thread Starter
Addicted Member
Re: Need some help
I think i may have found one of my main problems, i already tried changing the 127.0.0.1 to the other IP and it didn't work but my problem was that the timer was acting too fast, before i could get a connection, i tried setting the timer interval to 0 and it worked on my network. I just have to test out of the network
-
Feb 9th, 2006, 03:31 PM
#4
Thread Starter
Addicted Member
Re: Need some help
no, it wont work over a non-network connection
-
Mar 13th, 2006, 09:25 PM
#5
Thread Starter
Addicted Member
Re: Need some help
I don't think this is a problem with my firewall becuase I turned it off to try.
Resizing
System Balloons
If your question is answered, please mark the thread resolved by pulling down the Thread Tools menu and clicking the Mark Thread Resolved button.
Remember to rate a post if you find it helpful 
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
|