473,410 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Chat Client Help

Alright well I had a question before when i was a noob and posted here and got such a great response this has become my main vb site. Anyways I have a comp that cant run msn due to it being a piece of crap :P so I decided to make a chat client with winsock and direct ip's.

Basically what it does is gives you the option of connecting to the ip or listening for incomming connections from an ip. The problem is i cant get winsock to send a connection request to the ip. I made it go through port 2 since ive never encountered anything using port 2 and its a default port so I figured I would be avoiding an error there. So I used a port scanner and scanned to see if port 2 was open and not realising port scanners send connection requests to the specified ports. Once it scanned port 2 I got a message on my main form saying "my ip" has requested a connection do you accept? (I made a msgbox under Winsock1_Connection request so that was supposed to happen) So I guess nothing is wrong with that part is just the sending of the connection request that wont work.

Screenshot of the forms so you can see what im talking about:



Also theyre on two different forms the Menu is the main form and once your connected then Menu hides and Chat comes up.

Heres my code so you can understand what im doing and where i went wrong
Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub cmdConnect_Click()
  3. On Error Resume Next
  4.         If txtIp.Text = W1.LocalIP Then
  5.             MsgBox "You cannot connect to yourself."
  6.             txtIp.SetFocus
  7.             txtIp.Text = ""
  8.         End If
  9.     W1.RemoteHost = txtIp.Text 'tells the winsock which IP we should connect to.
  10.     W1.RemotePort = 2 'tells the winsock which port we should connect to.
  11.     W1.Connect
  12. End Sub
  13.  
  14.  
  15. Private Sub cmdExit_Click()
  16.     Unload Me
  17. End Sub
  18.  
  19. Private Sub cmdListen_Click()
  20.     W1.RemoteHostIP = txtIp.Text
  21.     W1.LocalPort = 2
  22.     W1.Listen
  23. End Sub
  24.  
  25. Private Sub Form_Load()
  26.     Label3.Caption = " Your IP: " & W1.LocalIP
  27. End Sub
  28.  
  29. Private Sub label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  30. If Button = 1 Then
  31. ReleaseCapture
  32. SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
  33. End If
  34. End Sub
  35.  
  36. Private Sub lblBackground_Click()
  37.  
  38. End Sub
  39.  
  40. Private Sub W1_Connect() 'When someone Connects to your server
  41. MsgBox W1.RemoteHostIP & " Connected!" 'Show an MSGbox with the remoteIP
  42. Me.Hide
  43. frmChat.Show
  44. End Sub
  45.  
  46.  
  47. Private Sub W1_ConnectionRequest(ByVal requestID As Long)
  48. Dim Message As String
  49.  
  50. Message = MsgBox(W1.RemoteHostIP & " Has requested a connection with you." & vbCrLf & "Do you accept?", vbYesNo + vbInformation, "Connection Request")
  51.     If Message = vbYes Then
  52.         Me.Hide
  53.         frmChat.Show
  54.     End If
  55. End Sub
  56.  
Also This is my chat part code (Doesnt matter as much as the connecting part.)
Expand|Select|Wrap|Line Numbers
  1. Private strDisplayName As String
  2.  
  3. Private Sub cmdClose_Click()
  4.     Unload Me
  5.     frmMenu.Show
  6. End Sub
  7.  
  8. Private Sub cmdExit_Click()
  9.     Unload Me
  10.     frmMenu.Show
  11. End Sub
  12.  
  13. Private Sub cmdSend_Click()
  14.     txtChat.AddItem strDisplayName & ": " & txtMessage.Text
  15.     txtMessage.Text = ""
  16. End Sub
  17.  
  18. Private Sub Form_Load()
  19.     strDisplayName = InputBox("Please enter your display name", "Display name")
  20.     txtChat.Clear
  21.     txtChat.AddItem "Welcome to HaggardSmurf's direct IP chat client. "
  22.     txtChat.AddItem "Your connected with: " & W1.RemoteHostIP
  23.     Label1.Caption = "  Direct Chat"
  24. End Sub
  25.  
  26. Private Sub label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  27. If Button = 1 Then
  28. ReleaseCapture
  29. SendMessage Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
  30. End If
  31. End Sub
  32.  
  33. Private Sub Timer1_Timer()
  34.     If txtChat.AddItem Then
  35.         frmChat.SetFocus
  36.         txtMessage.SetFocus
  37.     End If
  38. End Sub
  39.  
  40. Private Sub txtMessage_KeyDown(KeyCode As Integer, Shift As Integer)
  41.     If (KeyCode = vbKeyReturn) Then
  42.         cmdSend_Click
  43.     End If
  44. End Sub
  45.  
Any help on how to make them connect would be appreciated. :P
Dec 6 '06 #1
0 1136

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ali | last post by:
I'm trying to write a really basic chat program that allows 2 client programs to send messages to each other via a server. I've managed to write the code so that both clients can connect to the...
3
by: preet | last post by:
What I am trying to do is to develop a dhtml based chat system. So far everything is working as planned, took me over 6 hours to get it working, but I am pleased with the results, it is...
3
by: John Wright | last post by:
I am trying to create a very simple chat program using UDP through a web page. I am having problems getting this going. All the examples I've seen deal with remoting or application variables, or...
2
by: Ahmed | last post by:
Hello everyone, I am designing a chat program for a company. The program will be used locally(through lan). I am progamming the chat program using VB.NET windows application. Lets consider the...
0
by: Chris | last post by:
Hi, Sorry for reposting but I changed my code and received a new error message so I thought I would try it on the group again. I have a working server and this is meant to be a chat client using...
1
oll3i
by: oll3i | last post by:
how do i run this example ? with openjms package com.ociweb.jms; import java.io.*; import javax.jms.*; import javax.naming.*;
1
eyeofsoul
by: eyeofsoul | last post by:
i have build the gui but i am having problem with implementing the tcp/udp. can somebody help me. i have server and client. the server can chat with the client. when i tried to to use the udp of tcp...
3
by: John Dalberg | last post by:
I am looking for an asp.net based chat software. I have looked at some (asp.net and php based) and they consist usually of a javascript piece where the web user (visitor) initiates a chat from a...
3
by: clawsy | last post by:
I develop a chat (server and client) using Sockets. It's working on LAN but when I try to connect the client to the server using my public IP address it says it cannot connect to that address. For...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.