TCP Networking and Desktop Applications - qt

I made a two players "paint", it's like black screen and you draw with only one color, thats it. Your friend does the same. I've used Qt C++ for GUI and SFML for the drawing part. And for networking, I'm really new at this, I followed SFML guides about TCP socketing thing and its working really fine at the moment. Only problem is, I must open a port to be server, so my friend can connect me with my ip and with the port I've opened. It's ok when I use it but if I want to share this program with everyone, some people will have bad time when they can't open port.
Is there any other way to connect without opening port to be server, OR Is there any port that every computer already allows you to use it. We tried port 80 but it doesn't seem like working.

You have several options:
Open different ports for different clients.
Serve them on the same port in different threads.
Serve them on the same port in different processes.
Serve them on the same port in an async manner.

Related

Why can't I run two USB serial adaptors on the same machine?

My work involves interacting with legacy hardware that uses serial ports. I often have to monitor more than one serial line, and for the purpose I have a couple of the common USB serial adaptors. When I connect both of them to the same (Windows 10) machine, irregularities show up. Both ports show up in device manager, but only the first one that I plug in to the USB connector works. The other one indicates port not open when I try to send data via RealTerm.
I have also seen the situation where when I plug the second adaptor in, its port comes up, but the one for the other adaptor disappears. Does anyone know a way that two devices can happily coexist on the one machine? Thanks in advance.
Just ion case this helps anyone in the future......
The problem seems to be caused by the fact that one of the adaptors was coming in via a (powered) USB hub. When I liberated another native port on the machine so I could host both serial adaptors directly, everything worked fine.
Not worth hunting the cause down, a solution is at hand.

Can't access device through network

I'm trying to interface a device with python.
The device is connected to another machine in the same network (the university network) and I know it's Port number.
I can access the device from the PC where it is plugged with the following code:
dev = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
dev.connect(('137.195.53.140',51019))
where '137.195.53.140' is the PC ip, and 51019 is the port number.
However, if I try the same from another machine, ipython gets stack at the command "dev.connect(('137.195.53.140',51019))", and when I abort the evaluation and then look at "dev" I get this:
<socket.socket fd=15, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('137.195.204.85', 50393)>
where '137.195.204.85' is the IP of the machine I'm using, and the port number I've no idea.
Since ssh works with no problem within this network, I thought that my approach for accessing the device would have worked as well.
Does anyone have any clue for this? I'm sorry if I haven't been clear, but I know absolutely nothing of networking (and not very much of Python either tbh).
There's couple of things to consider:
Your university network ports
Your device's opened ports
Your network might have the 51019 port blocked. Also, ssh uses port 22 to make it's connection. Every port is a world, so there's the chance that just because 22 is open, it doesn't mean that another is. School networks usually have a pretty rigid policy on port closing for security and blocking unwanted sites too.
You can test your device access by pinging it as
$ ping 137.195.204.85
If that works, then you can go trying different ports

Send files from Qt application on ethernet

I want to send files from Qt Application using Ethernet.As I click push Button the files must be transfered.
so my Question is:
Q: what are the configuration required because IP ,Net Mask is fixed in my device I am using :AM335x
:Linux OS
:Qt application
I am new to TCP/IP tell me how to proceed;
from Ethernet I am able to download Qt application executable file from PC to my device(AM335x) and it is running well .
But I want to send files from Am335x device to other device or PC.
Regards
Praveen
Basically what you want to be using is the Qt Network module. You can read about that here:
http://qt-project.org/doc/qt-5.0/qtnetwork/qtnetwork-programming.html
And find a class list here:
http://qt-project.org/doc/qt-5.0/qtnetwork/qtnetwork-module.html
Very briefly the two main classes you can use for TCP communication are QTcpServer and QTcpSocket. You can set up the server to listen for connections and it will return a QTcpSocket to do the actual communication. You can use the QTcpSocket for any outgoing communication.
If you don't want to use TCP, you can use datagrams (simpler, but ultimately less reliable). Here QUdpSocket is the main class to use, both for sending and receiving (you need to bind the socket to a port on your machine to receive).
It would be fairly easy to write a custom program to do simple file transfer based on these classes, however you can also look at higher level protocols designed to deal specifically with files.
For simple interaction with an FTP server at the other end of the connection you can use the QFtp class. An example of an FTP client application is here. Writing an FTP server in Qt would be rather more complicated, however you can look here: https://code.google.com/p/qt-ftp-server/.
All of this of this of course assumes that the Ethernet connection has been set up properly and that your computer has a valid IP address. Bear in mind that Ethernet is a link layer protocol and forms the raw basis for the higher level IP and TCP protocols. The idea of the higher level protocols is that they can used over a variety of link layers throughout the internet. It would be very unusual to write a program that interacts directly with a link layer protocol (unless of course you are writing a network stack for an OS).
On most networks configuration of IP addresses/netmasks etc is handled by a DHCP server running on one of the devices, most commonly on the router connecting everthing (if you have DHCP already running, then you probably don't have to worry). Without DHCP you can usually configure a static address and netmask on most devices. Choosing them is a fairly simple procedure. This page has a fairly good introduction to the concepts.
At first, you must be sure, that the target you want to send file to, is reachable. Use ping. If ping call is successful, then you can go further. Otherwise you should check your network settings to comply with your LAN.
You have then various ways to send files: FTP, HTTP, via netcat, using CIFS etc.

Peer-to-peer chat

im wondering if it's possible to create p2p chat application without server(so there is no need in external static ip.Is it true?)?
EddieC is right if the computers are located inside the same sub-network (LAN) or if the computers'ip is their interface to the Internet (WAN public ip). In that case, you can just use the ip's and ports directly.
However, usually, knowing the computers ip is not enough because the machines are located behind routers inside sub-networks. Thus, because the computers are hidden behind the routers, you will have to configure the routers to foward the packets to the right computers as function of the ports used.
Have a look at : http://wiki.vuze.com/w/Port_forwarding
If you do not want to use ip's because they are dynamic, you can configure urls with Dynamic DNS services.
Good luck
It is possible. But you must have someway for one computer to tell the other computer what their IP number is. You could email it to your friend or call them on the phone or post it on a message board.
If this program only has to work on a local network (LAN), there is something called broadcasting which might be of interest to you. It allows a packet to be sent out to every device on the network without having to know their IPs (then other instances of your program could reply with the IP of their machines so you could set up proper connections).
This won't work over the internet, though (imagine being able to broadcast to every computer connected to the internet!).

Sniffing data from a switch

I have 2 network devices that talk to each other over Ethernet. I would like to sniff the traffic using Wireshark. But the devices are going through a switch. The switch routes the traffic to only the ports that need the data.
At another location I have a hub. All the traffic is repeated across all the ports.
Is there a way to tell the switch to send the traffic down my port also?
EDIT: This is an unmanaged switch.
You might want to look into ARP spoofing.
http://en.wikipedia.org/wiki/ARP_poisoning
Since this is an unmanaged switch, the only way that I can think of is to temporarily put a hub between the switch and one of the devices you want to monitor, then plug a laptop into that hub to do the monitoring. The laptop should now see all traffic between the device and the switch.
This is pretty easy since you can do it at the location of one of the devices. You just need a hub, two more lengths of CAT cable and the computer you are using to monitor with.
The switch may have a management interface that lets you do that. Be warned that if you do, you'll wreck performance on the switch since everything attached to it will now have to deal with collisions.
If the switch is a managed switch, it likely has a mode to act like a hub. Just be careful not to leave it like that.
Some will also have ways to mirror ports and such as well. You need to find out what kind of switch it is.
RE Edit: If it is unmanaged, then you are boned. Use a hub, a managed switch or run wireshark on the computer(s) affected.
You could try a port redirector, like this one. You would configure one device to talk to your computer instead of the other device, and the redirector will send the data to the real target. There are several programs like this out there, or you could write your own.

Resources