We help IT Professionals succeed at work.

Visual Studio 2005 Socket Chat, Where to start?

3,174 Views
Last Modified: 2013-11-26
I want to create a chat program using sockets. i am new to sockets, tho i have created a VB6 app using winsock.

I'm not sure where to start... guidence would be much apreciated.
Comment
Watch Question

Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:

Author

Commented:
These are both in C, i already found these... as im know zero C, these arent very helpful.
Project manager
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
On your suggesiton using http://www.codeproject.com/KB/IP/TCPIPChat.aspx?print=true after converted using http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx it produces code snippet, which produces 3 erros on the first section of code...

Error      1      Type 'IPEndPoint' is not defined.
Error      2      Type 'Socket' is not defined.
Error      3      Type 'Socket' is not defined.      
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 8000);
Socket newsock = Socket(AddressFamily.InterNetwork,
                   SocketType.Stream, ProtocolType.Tcp);
newsock.Bind(localEndPoint);
newsock.Listen(10);
Socket client = newsock.Accept();

Open in new window

Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
Do you have all the references ?
Do you have all the code converted ? Probably you'll need a class called IPEndPoint

Author

Commented:
ok ill go on with the code, and let you know when i have completed it.
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
If you have converted all the code, let me know where the errors are and I'll try to help you solve them

Author

Commented:
Code snipped wont convert, get
Conversion was attempted, however the following errors were reported:
-- line 1 col 12: Unexpected identifier

bwListener = new BackgroundWorker();
bwListener.DoWork += new DoWorkEventHandler(StartToListen);
bwListener.RunWorkerAsync();
 
private void StartToListen(object sender , DoWorkEventArgs e)
{
   this.listenerSocket = new Socket(AddressFamily.InterNetwork, 
                           SocketType.Stream, ProtocolType.Tcp);
   this.listenerSocket.Bind(
               new IPEndPoint(this.serverIP , this.serverPort));
   this.listenerSocket.Listen(200);
   while ( true )
      this.CreateNewClientManager(this.listenerSocket.Accept());
}

Open in new window

Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
I guess this should do the trick. Perhaps there is a problem with the while (true)
bwListener = New BackgroundWorker()
bwListener.DoWork += New DoWorkEventHandler(StartToListen)
bwListener.RunWorkerAsync()
 
Private  Sub StartToListen(ByVal sender As Object, ByVal e As DoWorkEventArgs)
   Me.listenerSocket = New Socket(AddressFamily.InterNetwork, 
                           SocketType.Stream, ProtocolType.Tcp)
   Me.listenerSocket.Bind(
               New IPEndPoint(Me.serverIP , Me.serverPort))
   Me.listenerSocket.Listen(200)
   while (True)
      Me.CreateNewClientManager(Me.listenerSocket.Accept())
End Sub

Open in new window

Author

Commented:
that has 19 errors on its own...

Error      3      Name 'bwListener' is not declared.
Error      4      Type 'DoWorkEventHandler' is not defined.
Error      5      Name 'bwListener' is not declared.      
Error      6      Type 'DoWorkEventArgs' is not defined.      
Error      7      'listenerSocket' is not a member of 'BxB_Ultimate.ChatWindow'.      
Error      8      Expression expected.      
Error      9      Expression expected.      
Error      10      Expression is not a method.      
Error      11      Method arguments must be enclosed in parentheses.
Error      12      End of statement expected.
Error      13      'listenerSocket' is not a member of 'BxB_Ultimate.ChatWindow'.
Error      14      Expression expected.      
Error      15      Syntax error.      
Error      16      'listenerSocket' is not a member of 'BxB_Ultimate.ChatWindow'.      
Error      17      'While' must end with a matching 'End While'.      
Error      18      'CreateNewClientManager' is not a member of 'BxB_Ultimate.ChatWindow'.
Error      19      'listenerSocket' is not a member of 'BxB_Ultimate.ChatWindow'.
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
Did you try the compile the solution in c# so that you can be sure that it is a working example ?

Author

Commented:
i did compile to solution in C# and it does work, however, from the look of it, its not really built to be compatible with VB.Net as it doesnt seem to be built the same way i would have, but maybe thats just me.

im not sure why i cant find any VB.Net tutorials, is this something that cant easily be done in vb.net?
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
In the Microsoft VB101 samples of vb2003 (free downloads) there is a program that you can convert to vs2005.
Name--- Advanced .NET Framework (Networking) - Use Sockets
This uses both server and client sides.

Another example found
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2326120&SiteID=1
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
Found a vb.net article:
Creating a Multi-User TCP Chat Application
http://msdn2.microsoft.com/en-us/library/aa478452.aspx

Author

Commented:
unfortunatly, it will not compile in VS 2005... but i will go through and see if i can find out why..

seems to be line :   mobjListener = New TcpListener(5000)

Warning      1      'Public Sub New(port As Integer)' is obsolete: 'This method has been deprecated. Please use TcpListener(IPAddress localaddr, int port) instead.

Author

Commented:
Im working through the errors, i seem to be stuck on:

Error      1      Value of type 'System.Net.Sockets.TcpListener' cannot be converted
  Private mobjClient As TcpClient
  Private marData(1024) As Byte
  Private mobjText As New StringBuilder()
 
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim MyIP As Net.IPAddress = IPAddress.Parse("127.0.0.1")
 
        mobjClient = New TcpListener(MyIP, 5000)
 
    DisplayText("Connected to host" & vbCrLf)
 
    mobjClient.GetStream.BeginRead(marData, 0, 1024, AddressOf DoRead, Nothing)
 
    Send("New client online")
  End Sub

Open in new window

Author

Commented:
Sorry my bad.. past this one now

Author

Commented:
my main problem now is   mobjListener = New TcpListener(IPAddress.Parse("10.1.1.1"), 5000) means it is waiting for a connection from a particualr IP... am i correct? i listen for all IP's

i tried   mobjListener = New TcpListener(IPAddress.Parse("*"), 5000) and while it doesnt produce and error, when trying to connect the listen never pics anything up
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
my main problem now is   mobjListener = New TcpListener(IPAddress.Parse("10.1.1.1"), 5000) means it is waiting for a connection from a particualr IP... am i correct? i listen for all IP's

--> I wouldn't know. I haven't programmed a chat-application

Commented:
Another simple chat solution in its simpliest way

http://www.codeproject.com/KB/IP/c_sharp_remoting.aspx

use
http://www.carlosag.net/Tools/CodeTranslator/Default.aspx

for easy conversion to vb.net

vbturbo

Author

Commented:
Oddly enough, i did get a chance to test this across a network, and it worked, but i don't know why, as it seems that it was listening on the same IP it was sending... the thing that remains now, is it sorta hangs while its waiting for a connection, and XP/VIsta think its not responding.
Dirk HaestProject manager
CERTIFIED EXPERT

Commented:
I guess you'll have to rework the program a little bit so that you use threading.

Author

Commented:
Thanks

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.