Jump to content

Visual Basic TCP Messenger Help

I am working on a TCP Messenger in Visual Basic. I have created a client and server which uses TCP Clients and Listeners to send and receive messages. The client and server will successfully communicate over the local area network, however the client cannot communicate with the server if the server is hosted on a different network. I have forwarded the port (45576) but the client can still not connect. I checked the port using http://www.yougetsignal.com/tools/open-ports/ and the port is closed. I'm guessing this means the server isn't listening on the public IP just the local IP. I would like the client to be able to communicate with the server over the Internet / Public IP.

I would also like help in creating a contact system. The client will be able to see who is online and will be able to send private messages to specific users (Like Skype). I have tried to create a system but the server would no longer broadcast messages so I reverted the changes. I have attached both the server and client source code to this post.

My skype is thomascarteruk91 if anyone would like to speak to me there.

Thanks

Nossic IM.zip

Link to comment
Share on other sites

Link to post
Share on other sites

Have you forwarded the port in the router's firewall, and allowed communication through the server's firewall on that port/application?

 

And about the contact system, how did you design your initial attempt?

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

Yes, I did allow the program through the firewall but still nothing. Originally for the contact system I create an ArrayList. Every time a client connects to the server their username was added to the ArrayList. When they disconnected their name was removed. However the server would no longer broadcast messages. The server already stores connected IPs to a Hashtable. I thought about using this list but I could not figure out how to get the username from the IP.

Link to comment
Share on other sites

Link to post
Share on other sites

Yes, I did allow the program through the firewall but still nothing. Originally for the contact system I create an ArrayList. Every time a client connects to the server their username was added to the ArrayList. When they disconnected their name was removed. However the server would no longer broadcast messages. The server already stores connected IPs to a Hashtable. I thought about using this list but I could not figure out how to get the username from the IP.

 

About the first problem, you've clearly got a configuration problem. Your router is probably not correctly configured to redirect the port to the server's local IP. Some routers are a pain to configure.

 

About the contact system, I'd recommend you to create an entity (e.g. a class) which holds both a username and their IP (along with a bunch more data you might want to store). Your HashTable could use their usernames (or their IP) as a key and this class as value.

I haven't looked at your code, but how are you making the server broadcast messages? I'd recommend you to create a new thread to manage each ongoing conversation, so that you have a dedicated stream of bytes in each (client1, server, client2) tuple.

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

I have fixed my first issue. For broadcasting messages the server is creating a network stream to every connected IP and is writing the text to that stream.

Link to comment
Share on other sites

Link to post
Share on other sites

I have fixed my first issue. For broadcasting messages the server is creating a network stream to every connected IP and is writing the text to that stream.

 

So, at its current state, if you send a message to the server, every single user (other than the one that sent the message) connected to the server gets the message? Or did I get that wrong?

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

That is correct. I want to make it so that messages can only be sent to a specific user.

Link to comment
Share on other sites

Link to post
Share on other sites

That is correct. I want to make it so that messages can only be sent to a specific user.

 

There are 2 simple ways to do this:

  1. Create an entity (e.g. a class) which represents a "message packet". This entity should store information such as source IP, destination IP (or username), message length, the message itself, etc.. Implement a method which converts all this data into streamable data. Once you want to send a message, in the source client create a message packet with the desired message and destination, and write that to the server stream. Once the server gets this data, it would reconstruct the packet, analyze the data, and redirect it to the destination client's stream.
  2. Use a multi-threaded approach. This is very simple code, so there's not much to look out for in terms of critical code (except for some synchronization with the HashTable manipulation). For each conversation that is "started", create a new thread on each of the clients and the server. So, for each conversation there would be a new TCP connection from client1 to the server, and from the server to client2. This system would have to rely on a command-based conversation between clients and the server (to negotiate new ports and such). This is probably the worst I could do at explaining this idea. lol

The 1st idea is more along the lines of what you're looking for (and it's simpler). I hope my explanations aren't too confusing.  :ph34r:

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

Your explanations are perfect and have helped a lot. I will attempt the first idea and will report any issues I encounter. Thanks!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×