Click here to Skip to main content
14,547,071 members

C / C++ / MFC

 
GeneralRe: How to make a Windows service to manage SQLite DB Pin
Richard MacCutchan2-Nov-15 6:25
mveRichard MacCutchan2-Nov-15 6:25 
GeneralRe: How to make a Windows service to manage SQLite DB Pin
intelstar venus2-Nov-15 6:44
Memberintelstar venus2-Nov-15 6:44 
QuestionRe: How to make a Windows service to manage SQLite DB Pin
David Crow2-Nov-15 9:14
MemberDavid Crow2-Nov-15 9:14 
AnswerRe: How to make a Windows service to manage SQLite DB Pin
intelstar venus2-Nov-15 21:28
Memberintelstar venus2-Nov-15 21:28 
AnswerRe: How to make a Windows service to manage SQLite DB Pin
jschell3-Nov-15 16:12
Memberjschell3-Nov-15 16:12 
GeneralRe: How to make a Windows service to manage SQLite DB Pin
intelstar venus4-Nov-15 1:05
Memberintelstar venus4-Nov-15 1:05 
GeneralRe: How to make a Windows service to manage SQLite DB Pin
jschell7-Nov-15 4:58
Memberjschell7-Nov-15 4:58 
Questionsocket:send integer Pin
Member 114755491-Nov-15 4:51
MemberMember 114755491-Nov-15 4:51 
how can i send integer ??Confused | :confused:
---help---

/*
    Clent socket tcp
*/
#include<stdio.h> //printf
#include<string.h>    //strlen
#include<sys/socket.h>    //socket
#include<arpa/inet.h> //inet_addr
 
int main(int argc , char *argv[])
{
    int sock;
    struct sockaddr_in server;
    char message[1000] , server_reply[2000];
    int a; 
    char r1; 
     
     
    //Creation d1 socket
    sock = socket(AF_INET , SOCK_STREAM , 0);
    if (sock == -1)
    {
        printf("impossible de creer une socket\n");
    }
    puts("Socket creer!!!! good job");
     
    server.sin_addr.s_addr = inet_addr("127.0.0.1");//adresse ipv4
    server.sin_family = AF_INET;// famille d'@
    server.sin_port = htons( 8880 );//**en utilisent big endien NBO   pour la sérialiser , htons (host to network short) 
 
    //Connection au serveur

  puts ("connection au serveur\n") ;
    if (connect(sock , (struct sockaddr *)&server/*pointeur sur l'@ du serveur est qui est passé en parametre**/ , sizeof(server)) < 0)
    {
        perror("peut pas connecter au serveur");
        return 1;
    }
     
    puts("vous etnSes Connecté\n");
         //communition server
    while(1)
    {
        printf("Enter votre nbres : ");
        scanf("%d " ,&a );
        
         
        //envoyer data
        if  (( send(sock , (char * )& a , sizeof(&a) , 0) < 0)  ) 

        {
            puts("l'envoie a ete echoué");
            return 1;
        }
         
        //la réponse du serveur
        if( recv(sock , (char *)& a , 2000 , 0) < 0)
        {
            puts("recv echoué");
            break;
        }
         
        
    }
     
    close(sock);
    return 0;
}


/*
    C socket server TCP
*/
 
#include<stdio.h>
#include<string.h>    //strlen
#include<sys socket.h="">
#include<arpa inet.h=""> //inet_addr
#include<unistd.h>    //write
 
int main(int argc , char *argv[])
{
    int socket_desc , client_sock , c , read_size,read_size1;
    struct sockaddr_in server , client;
    char client_message[2000];
    int a;
    char t ;
     
    //Creation d1 socket
    socket_desc = socket(AF_INET , SOCK_STREAM , 0);
    if (socket_desc == -1)
    {
        printf("on peut pas creer la socket");
    }
    puts("Socket bien creer");
     
    //Preparer sockaddr_in structure
    server.sin_family = AF_INET;//***fammille d'@
    server.sin_addr.s_addr = INADDR_ANY;//********@ qqn
    server.sin_port = htons( 8880);//*****en utilisent big endien NBO   pour la sérialiser , htons (host to network short) 
     
    //Bind
    if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
    {
        
        perror("bind. Error");
        return 1;
    }
    puts("bind attaché");
     
    //Listen
    listen(socket_desc ,3);
     
    //Accept connection
    puts("attedez une connection...");
    c = sizeof(struct sockaddr_in);
     
    //accept conection de client qui vient de se connecter!
    client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c);
    if (client_sock < 0)
    {
        perror("accept failed");
        return 1;
    }
    puts("Connection accepté");
     
    //Receoit les message de client
    if ( (read_size = recv(client_sock , (char *)&a , 2000 , 0)) > 0 ) 
    {
        
        write(client_sock , &a , sizeof(&a)); 
                
    }
     
    if(read_size == 0)
    {
        puts("Client disconnected");
        fflush(stdout);
    }
    else if(read_size == -1)
    {
        perror("recv failed");
    }
     
    return 0;
}

<pre lang="c">

QuestionRe: socket:send integer Pin
Richard MacCutchan1-Nov-15 5:36
mveRichard MacCutchan1-Nov-15 5:36 
AnswerRe: socket:send integer Pin
Member 114755496-Nov-15 4:15
MemberMember 114755496-Nov-15 4:15 
GeneralRe: socket:send integer Pin
Richard MacCutchan6-Nov-15 4:17
mveRichard MacCutchan6-Nov-15 4:17 
AnswerRe: socket:send integer Pin
Jochen Arndt1-Nov-15 21:07
professionalJochen Arndt1-Nov-15 21:07 
GeneralRe: socket:send integer Pin
Member 114755496-Nov-15 4:16
MemberMember 114755496-Nov-15 4:16 
Questionuint32_t result of uint16_t addition Pin
elelont230-Oct-15 3:44
Memberelelont230-Oct-15 3:44 
AnswerRe: uint32_t result of uint16_t addition Pin
Jochen Arndt30-Oct-15 4:00
professionalJochen Arndt30-Oct-15 4:00 
AnswerRe: uint32_t result of uint16_t addition Pin
jeron130-Oct-15 4:08
Memberjeron130-Oct-15 4:08 
AnswerRe: uint32_t result of uint16_t addition Pin
CPallini30-Oct-15 4:24
mveCPallini30-Oct-15 4:24 
AnswerRe: uint32_t result of uint16_t addition Pin
R. Erasmus3-Nov-15 23:48
MemberR. Erasmus3-Nov-15 23:48 
QuestionChange menu item text Pin
_Flaviu29-Oct-15 3:25
Member_Flaviu29-Oct-15 3:25 
AnswerRe: Change menu item text Pin
Richard MacCutchan29-Oct-15 5:20
mveRichard MacCutchan29-Oct-15 5:20 
GeneralRe: Change menu item text Pin
_Flaviu5-Nov-15 1:29
Member_Flaviu5-Nov-15 1:29 
GeneralRe: Change menu item text Pin
Richard MacCutchan5-Nov-15 5:32
mveRichard MacCutchan5-Nov-15 5:32 
GeneralRe: Change menu item text Pin
_Flaviu5-Nov-15 21:14
Member_Flaviu5-Nov-15 21:14 
GeneralRe: Change menu item text Pin
Richard MacCutchan5-Nov-15 23:20
mveRichard MacCutchan5-Nov-15 23:20 
Questionappending to file Pin
Member 1208455926-Oct-15 18:56
MemberMember 1208455926-Oct-15 18:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.