I want to attempt to write a peer to peer chat client that I can use with one of my friends, both of us are running fedora 17. After doing some reading I want to achieve this by sending the messages through TCP sockets, but I'm not sure what library/libraries I need to use to do this. Honestly I'm a little worn out from trying to get the boost libraries to compile and figuring out how to link them, the whole process just seems unnecessarily complicated to me, seeing that I use vim because I personal prefer not to use IDEs. Are there any standard C++ libraries that allow for packets of data to be sent from one device to another using tcp sockets?
You don't need any special libraries, it's all included in the standard C library (libc) that all applications are linked with.
The things you have to do are the usual for a client:
Find the IP address of the host (getaddrinfo)
Create the socket (socket)
Connect to the server (connect)
Send and receive data (write and read)
Close connection when done (close)
There are many tutorials on network programming on the Internet, almost all of them have examples showing char servers and clients.
I think you just need C++ and standard library.
you need to write a program binding to the concerned port and connectting to another computer by TCP .
Just Sending and receiving msgs through socket connection.
Related
long time reading, first time posting.
I dont't know if it is maybe stupid, but I want to build a "simple" Server/Client for logging multiple Application in one point.
All with boost.
Server writes to log file (that is no Problem, working good with boost log)
Server should accept multiple clients/applications
there should not be a new connection for each log msg, I think this would lead into a lot overhead in create connections
I have a working server/client with boost asio tcp ip iostream, but only to open connectin, send the msg and after it closeing the connection. This works fine with 2 applications-
But as I said, this leads in a big overhead in opening connections.
Anyone has a good idea to accomplish idea, in open the connection only once for each apllication?
I going to create kernel mode driver level app that establish a TCP connection, here is my requirement:
I don’t want pass data to user-mode
I don’t want use winsocket and OS socket library
I need to just pass tcp packet to a library and
the library create simple TCP-client or TCP-Server connection for me. It should perform all TCP connection requirements such as tcp handshake, generate packet, calculate checksum, set TCP flags and acknowledgment then give the new packet to me so I can send the packet to my network adapter.
Do you know exiting TCP implementation that it does not use OS socket library?
I think the proper way to ask this question is this:
What is the proper way to do TCP sockets within kernel code?
And I'm not sure you want to do TCP just at the packet level, because you'll also likely want to handle TCP segmentation, IP fragmentaion, sending only when the remote window size permits it, and ACK generation. In other words, if you're doing a TCP server within kernel mode, you want the whole kernel TCP stack.
In any case, Bing or Google around for "kernel sockets" or "ksocket".
For Linux: http://ksocket.sourceforge.net/ Also, check out this example for UDP.
For Windows: Go to this page and downlaod both the HttpDisk and KHttpd samples. Both feature a windows device driver than makes use of a similar "ksocket" library. (Look for ksocket.c and ksocket.h in each)
For Linux, use the kernel_*() versions of the usual socket API, i.e. kernel_bind(), kernel_listen(), kernel_accept(), kernel_connect(). They're in #include <linux/net.h> and are used in ways very similar to "normal" sockets.
Solaris has very similar interfaces, there named ksocket_*(), see #include <sys/ksocket.h> for references.
For the *BSD UN*X flavours, Apple's Network Kernel Extensions Guide gives some details (also with references to the corresponding interfaces on Free/Net/OpenBSD).
Don't know about Windows.
Firstly I think I need to say that I'm still learning C++ so apologies if this is blindingly obvious/simple.
I'm trying to use the libevent library (by trying I've looked through code in the sample folder and tested some) in my C++ program to consume an http stream. I'm wondering if anyone can provide me with an example of how I'd go about connecting to a URL e.g. live.domain.com, sending the appropriate headers, read the data returned and send data back over the same connection...
I'm not sure libevent does any blocking connections but just to be explicit, I'm after non-blocking samples.
Why am I trying to do this?
I'm using an API which requires you to open a connection and it keeps it alive unless there's an error. It'll periodically send status texts to the connected client until it receives a string with an ID over the same connection. At which point it starts sending data back about the ID given... I'm not entirely sure sending data back over the same connection after the initial request is strictly compliant but that's what the server expects so it'll work...if I knew how
Thanks in advance
Yuck. Given that this isn't really HTTP, I don't think you're going to be happy using a HTTP library - even if you get it to work today after a lot of frustration, it could easily be broken tomorrow. This is too rare to be a supported feature.
But...it sounds like it's also simple enough that you could just open a raw TCP connection with libevent, manually send something that looks kind of like an HTTP request, and handle it with raw sockets from there. You don't want the extra stuff a HTTP library gets you anyway (additional transfer/content encodings, proxy support, SSL, compatibility with other protocol versions, ...)
As far as examples go, look at the libevent book. In particular, the a "Trivial HTTP v0 client" that seems very close to what you want. Good luck!
I have a small project that I've been working on in C++, and due to the nature of what it does, I need to insert packets in to a live TCP stream. (The purpose is innocent enough, http://ee.forumify.com/viewtopic.php?id=3299 if you MUST know)
I'm creating a level editor for a game, and due to the nature of the handshakes, I can't simply establish a new connection with a high level library such as WinSock. Until now, it has relied on Winsock Packet Editor to do the dirty work, but if I were to let the application handle it all, it would make everyone happy.
So my question is this: Is there an API somewhere that will allow me to take control of a live TCP stream, and preferably one that keeps it valid after it finishes? And I would prefer to not have to inject any DLLs. Also, Detours is a no-no as I'm using GCC/Mingw.
I've toyed around with WinPCap and I have some working code (I can collect a packet, and from that generate a proper packet to send) but since it operates at such a low level, I cannot anticipate all of the potential protocols that the end user might use. Yes, chances are that they'll be using IPv4 over Ethernet, but what about those people who still use PPP, or some other obscure protocol? Also, the connection gets dropped by the client application after mine is done with it, as the latest ID values in the packets have changed and the client assumes that it has disconnected.
So, if anyone could provide a high-level TCP stream manipulator, I would be very happy. If not, I'll just continue tinkering with WinPCap and tell all the dial-up users to go get better internet.
Target platform: Microsoft Windows XP through Windows 7
Create a separate process to bind to a local port. When the initial tcp stream is created, proxy it through that process, which can then forward it on to the network. When you need to 'inject' into the stream you can have this proxy process do it. Just a thought.
you should look at the source code of ettercap http://ettercap.sourceforge.net/
or hunt, tcp hijacker http://packetstormsecurity.org/files/view/21967/hunt-1.5.tgz
Those 2 softs do what you're after.
I don't think there's any sensible API that will allow you to hijack a TCP stream. Such a thing would, inherently, be a security problem.
Can you insert your program as a proxy for the connection in question? That is, get the program that opens the connection to open it to your program, then have your program open the connection to the real target.
The idea is that if all the packets pass through your program anyway, then modifying the TCP stream becomes relatively trivial.
I want to send a file in C++ over network (for a chat program)
what should I do?
Take a look at http://www.boost.org/doc/libs/1_38_0/doc/html/boost_asio/examples.html . The Iostreams example should give you the first good step. Asio is a portable network library of the boost project. Boost is available for most platforms available today.
You can stream in the file and stream out it into the TCP stream.
Use Open source FTP library for more robust application .Read this thread for c++ based open soruce library.
Its quite easy. Set up a TCP/IP socket and then split the file into packets and send them across. TCP is reliable thus all the packets will arrive in the right order and it will handle re-transmission etc.
If, however, you need to use an unreliable transport (such as UDP) then look at stop and wait (Easiest), go-back-n or selective repeat (Which are both somewhat harder but far more efficient).
You can open a direct connection between the two and send the content the file. For that, one side will be the client and the other will be the sender.
You can see a simple implementation here.
You will be doing something called socket programming. Please refer Beej's Guide to Networking for all the details and the solution to your problem.