0

I'm new to internet-based / network programming, and this is my first time using packets in any language.

I want to create a console application that lets people connect to a chat room and talk to people. For the moment, I just want to send a receive a packet.

I am using TcpListener to recieve and TcpClient to send. I want it to be simple for people using it and don't want them to have to port forward in order to use it.

Can I send TCP without port forwarding or will I have to use something else?

Thanks in advance.

Visual Vincent
  • 18,045
  • 5
  • 28
  • 75
Sulphate
  • 103
  • 9
  • 2
    Your very best option is to have a public server which handles all the messages, then have your clients connect to it instead. When the server receives a message from one client it passes the message along to the correct recipient. -- A secondary, more complicated option is to perform [NAT traversal](http://serverfault.com/questions/604644/access-to-a-network-server-without-port-forwarding) (which in many cases require an external server anyway). – Visual Vincent Oct 04 '16 at 21:11
  • _"I am using TcpListener to recieve and TcpClient to send"_ is a red flag. TCP communication is bidirectional, you only need either at either side of the connection. – CodeCaster Oct 04 '16 at 21:17
  • What Vincent said. Plus, if I was a user of your application, how does your code discover the IP address of the person I wanted to talk to? – selbie Oct 04 '16 at 21:19
  • Sorry for not being specific, I have a TcpListener set up on a remote server, also on my friend's PC, and am using the TcpClient to send from my home PC. The application would be a chat box of all of the messages. I haven't exactly worked out what I'm going to do if and when I get to that stage, but for now I just want to successfully send a receive a packet. – Sulphate Oct 04 '16 at 21:44
  • In the meantime, so that you can test sending and receiving, in order to communicate with your friend's computer you could port forward _or_ use [**Hamachi**](https://www.vpn.net/). – Visual Vincent Oct 04 '16 at 23:15
  • Note that when using TCP, as far as you are concerned you are not sending packets. The sending and receiving of packets is hidden from you and done in the background. Rather you are sending (and/or receiving) a sequence of bytes. The bytes will arrive in the order you sent them, but the placement of bytes into packets will be determined by the networking stack, not by your app. – Jeremy Friesner Oct 05 '16 at 01:00

0 Answers0