Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm creating a server that will in most/all cases be run on the same machine as the client. The client will need to be able to send and receive messages from this server. Some of the received messages will not be answers to questions (such as with http requests). All the messages will hold is a string that the project then uses to determine what function needs to be run.
The question is "Do I need to connect on two ports: one for sending and one for receiving?" If I use tcplistener with C# and C++ POSIX for networking, can I just send and receive messages on the same port?
Yes. You can send and receive on the same port and that's the intended way to communicate with tcp.
EDIT
You have two actors, a host and a client.
The host... will open a local network port (that you specify) and listen for new connections and communications from clients.
The client... can (and probably should) choose it's own local port and connect to the host on the port you specified.
Both the host and client... can communicate over the established connection. The host can send data to the client as long as the client is listening.
Have the server bind to and listen on a well-known port. Have the client bind to any port (you can let bind pick for you) and connect to the server on its port. Exchange messages.
Yeah, there isn't a difference between tcp/ip.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am trying to do wireless communications between a PC and a Raspberry Pi using python's socket module. The problem is that the program on the PC is programmed in C# but the Raspberry-Pi is programmed in Python. How can I send a string from my computer so that the Raspberry Pi programmed in Python can read it?
A protocol like this is language-independent. That is one advantage of having such a concept.
If a server receives a connection request, it doesn't know or care what kind of code was used to create the connection and send the data (someone could even be typing it in by hand, in theory), all it cares about is that the data being sent is in the correct format (as defined by the protocol) and the messages follow the correct sequence etc, so that it can understand it.
This applies to all sorts of commonly-known protocols, such as TCP/IP sockets, or higher-level protocols which build on that, such as HTTP or FTP.
So as long as you know how to create code to initiate a socket connection in language A, and code to listen for connections in language B (or C or D, or even A again), then everything should work correctly.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am creating a peer to peer application in c sharp, I was wondering if it was possible to send a request to the other persons router over the internet and ask it to open port 1234, or if there is any other way of uploading and sending data without port forwarding, or even an application that i can port forward my router via command line or dll would be great. Please help me for this is making me frustrated.
There is no way for an outside app to tell a router to open a port to one of its local machines. This would be a huge security hole.
If a local machine wants access from outside, it could use UPnP (NAT Traversal) to tell the router to forward a port to it (or you could simply configure your router to forward the port).
If both peers are behind NAT with no access to port forwarding, you would have to use some 3rd party server that proxies the data.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am trying to build a chat app in c# that would work in the wan network.
There are 2 side in the app. Server side and client side.
In my thoughts i think that every message from client to client need to be passed to the server and the server will forward it to the right des client. The communications between the clients wont be directelly.
Is this the right model?
If yes, does the server need to have one socket that will listen to all clients? (Because every client sends his message to the same port at server).
Will the sever can handle management of million of messages on same port?
I think it is really up to what you want to accomplish, each choice has it's own pros and cons.
For example:
Using a centralized server can track messages , which users are online etc... but you will have to manage the ports for each connection (see explanation at the end of the answer for details).
Using a P2P model, you will not have the bottle neck and management required by the centralized server, but again it might be more of a hassle to manage a non centralized system (depends what exactly you want to accomplish).
If you are going to the centralized design, Typically You would have a server with a port that will listen for requests.
once a user wants to connect, the server will start a new thread for the client, and will assign a port for him (the thread will be typically from a thread pool and the port from a specific port range).
this will allow users to speak to the server in a non-blocking manner, and by that allow for multiple users to use the service simultaneously.
Take a look at SignalR and the chat system implemented using SignalR, Jabbr:
http://signalr.net/
http://about.jabbr.net/
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I've made a server/client application in C#.
My question is the following: Let's say a client is behind an NAT (Like a router) and tries to connect to a server. From the server's perspective, the server only knows the client's external IP address. How do you determine exactly which computer to send the packets to that is behind an NAT? I understand port forwarding from the router on the client's end is a common way of solving these type of problems but if you look at applications like Skype, port forwarding is not necessary to properly establish a connection between the server and however many clients behind the NAT. This question can be asked vice-versa as well (I.E: client to server behind NAT).
I'm pretty new at socket programming so I'd love to hear any guidelines or materials that I can read over to fully understand this stuff.
You shouldn't worry about NAT in the application layer. If you receive a message with an IP say 200.51.255.79 you can send the answer to the same IP. Routers will handle the NAT and further routing automatically. It's not like this with port forwarding of course but it is with NAT.
Skype works in a very interesting way to get around port forwarding and firewalls using a server sided database of current ips and ports where each user is waiting for a response. You should look that up on the internet for a full explanation. It's a really good read =).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
How can I in c# send Message box to remote computer? I have credentials of remote PC and know PC name. Can use for this purpose WMI?
Look into the NET SEND command. However, the messenger service needs to be enabled on the remote computer - you could use PSEXEC to start this.
I think you're asking how to send a message to a remote computer via c#. If so, you have several options see below:
Microsoft message queuing - Only if you need a super robust framework that gauarantees delivery of your message even if destination goes offline.
UDP multicast message - You can use the System.NET.Sockets namespace to send UDP packets and build a client to listen for them which can be run of n number of remote server. This is not error checking and if the remote server is not up then you are out of luck.
TCP socket connection - You can use the System.NET.Sockets namespace to send TCP packets and build a client to listen for them which can be run of n number of remote server. This is error checking and if the remote server is not up then you are out of luck.
Hope this gives you some direction.
Enjoy!