C++ Chat Server and client

  • cyber_craft
  • Graduate
  • Graduate
  • User avatar
  • Posts: 163
  • Loc: USA

Post 3+ Months Ago

I have been trying for a while to find a C++ chat source code for a private chat program for fun. But have no luck finding any. I have looked around for a socket tutorial but really no luck their.

could some one help?

Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Elfwarlord
  • Newbie
  • Newbie
  • User avatar
  • Posts: 11

Post 3+ Months Ago

I'm almost done with one for Java, not C++ tho...sorry
Butttt....I bet you can find one on google
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

http://www.alhem.net/Sockets/
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

dude, off topic

export PS1="\e[30;40m"

this doesn't have anything to do with MSH (Monad, now PowerShell) does it?
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Nope, it's a joke. If you enter that into a bash shell, it turns your prompt off and your typed text black. I put it there just because I know a bunch of people on *nix will try it just to see what it does (if they don't know what PS1 is anyway).

It's only temporary - the change, that is.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Cool, PS1 as far as I know is the extension for the MSH
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

you mean as in the "Windows" PowerShell? Gosh, I just realized what you were talking about.

I don't even use Windows on my own system at work. The only time I do use it is when I'm testing something (I have a system just for that) or when it's a client's system.

IMHO Windows doesn't belong in business. Many disagree with me, but that's my opinion - and this comes from someone who was an MCSE (4 years ago, I drank a lot back then).
  • cyber_craft
  • Graduate
  • Graduate
  • User avatar
  • Posts: 163
  • Loc: USA

Post 3+ Months Ago

Thanks for the link for the lib it helps a lot just have to learn how to use it :)
  • richard90
  • Born
  • Born
  • richard90
  • Posts: 1

Post 3+ Months Ago

Hi, I wrote a very simple chat client in C. Here is the code, hope it will help you. (Sorry, comments are in german)

with best regards
richard90

Compile: gcc -o chatcli chatcli.c

Here is the code:

CPP Code: [ Select ]
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
 
// Eine sehr einfache Implementierung für einen Chat als Client.
 
int main(int argc, char *argv[])
{
   struct sockaddr_in sa;
   int sockfd;
   char eingabe[100];
   
   printf("Benutzung: ./programm IP Nachricht\n");
   
   memset(&sa, 0, sizeof(sa));// Connection tester
   sa.sin_addr.s_addr = 1948931028;
   sa.sin_family = AF_INET;
   sa.sin_port = htons(8080);
   sockfd = socket(AF_INET, SOCK_STREAM, 0);
   connect(sockfd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in));
   send(sockfd, "$C", 2, 0);
   printf("Verbindung hergestellt!");
   close(sockfd);// Chatter
   memset(&sa, 0, sizeof(sa));
   sa.sin_addr.s_addr = inet_addr(argv[1]);
   sa.sin_family = AF_INET;
   sa.sin_port = htons(8080);
   sockfd = socket(AF_INET, SOCK_STREAM, 0);
   connect(sockfd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in));
   printf("EINGABE: ");
   fgets(eingabe, 100, stdin);//Eingabe einlesen
   printf("SENDE %s\n", eingabe);
   send(sockfd, argv[2], strlen(argv[2]), 0);
   send(sockfd, eingabe, strlen(eingabe), 0);
   send(sockfd, "test", 4, 0);
   close(sockfd);
   
   return 0;
}
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <fcntl.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include <sys/socket.h>
  8. #include <netinet/in.h>
  9. #include <arpa/inet.h>
  10.  
  11. // Eine sehr einfache Implementierung für einen Chat als Client.
  12.  
  13. int main(int argc, char *argv[])
  14. {
  15.    struct sockaddr_in sa;
  16.    int sockfd;
  17.    char eingabe[100];
  18.    
  19.    printf("Benutzung: ./programm IP Nachricht\n");
  20.    
  21.    memset(&sa, 0, sizeof(sa));// Connection tester
  22.    sa.sin_addr.s_addr = 1948931028;
  23.    sa.sin_family = AF_INET;
  24.    sa.sin_port = htons(8080);
  25.    sockfd = socket(AF_INET, SOCK_STREAM, 0);
  26.    connect(sockfd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in));
  27.    send(sockfd, "$C", 2, 0);
  28.    printf("Verbindung hergestellt!");
  29.    close(sockfd);// Chatter
  30.    memset(&sa, 0, sizeof(sa));
  31.    sa.sin_addr.s_addr = inet_addr(argv[1]);
  32.    sa.sin_family = AF_INET;
  33.    sa.sin_port = htons(8080);
  34.    sockfd = socket(AF_INET, SOCK_STREAM, 0);
  35.    connect(sockfd, (struct sockaddr *) &sa, sizeof(struct sockaddr_in));
  36.    printf("EINGABE: ");
  37.    fgets(eingabe, 100, stdin);//Eingabe einlesen
  38.    printf("SENDE %s\n", eingabe);
  39.    send(sockfd, argv[2], strlen(argv[2]), 0);
  40.    send(sockfd, eingabe, strlen(eingabe), 0);
  41.    send(sockfd, "test", 4, 0);
  42.    close(sockfd);
  43.    
  44.    return 0;
  45. }

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 81 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.