Kencas's Posts
Nairaland Forum › Kencas's Profile › Kencas's Posts
1 2 (of 2 pages)
Look for Definitive Guide to swing programming by John Zukowski.Its a good guide.Learn on The java 2d API.More info call 08034275706 or email kcjojo8@gmail.com |
This is for the server //socket.c //Developed by kencas #include <stdio.h> #include <netinet/in.h> #include <netdb.h> #include <sys/socket.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #include <ctype.h> #define SHMSZ 27 #define MAX 1000 int main(int argc, char *argv[]){ // get port number int port = atoi(argv[1]); // perform range check on port number if( port <= 1024 ){ printf("must use a port above 1024, terminate.\n" ;exit(1); } // fd and socket params int sockfd; struct sockaddr_in my_addr; struct sockaddr_in client_addr; socklen_t sin_size; int backlog = 5; int optval = 1; // create socket, test if worked sockfd = socket(PF_INET, SOCK_STREAM, 0); if( sockfd < 0 ){ perror("can't create socket, terminate.\n" ;exit(1); } // make socket re-use able in case of crashes/restarts int set = setsockopt(sockfd, SOL_SOCKET,SO_REUSEADDR, &optval, sizeof(optval)); if( set == -1 ){ perror("can't do setsockopt function, terminate.\n" ;exit(1); } my_addr.sin_family = AF_INET; my_addr.sin_port = htons(port); // automatically fill with my IP my_addr.sin_addr.s_addr = INADDR_ANY; memset(my_addr.sin_zero, '\0', sizeof my_addr.sin_zero); // try to bind sin_size = sizeof(struct sockaddr); int bind_result = bind(sockfd,(struct sockaddr *)&my_addr,sin_size); if( bind_result == -1 ){ perror("can't bind, terminate.\n" ;exit(1); } // try to listen int listen_result = listen(sockfd,backlog); if( listen_result == -1 ){ perror("can't listen, terminate.\n" ;exit(1); } // debug, show state of socket printf("listening on port [%d] , \n", port ); int new_fd = 0; char buffer[MAX]; int bytes = -1; // while forever while(1){ sin_size = sizeof(struct sockaddr_in); // accept incoming request new_fd = accept(sockfd, (struct sockaddr *)&client_addr, &sin_size); // valid file descriptor? if( new_fd != -1 ){ // debug printf("\naccept() connection %s",inet_ntoa(client_addr.sin_addr)); backlog--; if (!fork()) { char old[MAX]; int check = 0; FILE *fp; fp = fopen("serverLog.txt", "a+" ;fprintf(fp, "\naccept() connection %s",inet_ntoa(client_addr.sin_addr)); fclose(fp); // child doesn't need the listen socket! close(sockfd); // read from client do{ bytes = recv(new_fd, buffer, sizeof(buffer), 0); if (bytes < 0){ perror("Read socket" ;}else{ printf("%s \n",buffer); send (new_fd, buffer, bytes, 0) ; if( strncmp(old,buffer,2)){ check ++ ; if (check == 3) break; } strcpy(old,buffer); } }while (strncmp(buffer, "endn", 4) != 0 || bytes < 0 ) ; close(new_fd); // kill the child exit(0); } // parent does not use this! close(new_fd); } else { // non-fatal perror("could not accept request, but non-fatal, \n" ;} }// end while printf("Bottom of file, should never get here! \n\n" ;return 0; } // end of main read the input with any client from the port specified.Client could be Java,.NET etc Hope this helps Cheers |
I'm a C++ programmer.Do you have knowledge of C/C++?? email kcjojo8@gmail.com or call 08034275706 |
Guy thats a very good idea.Do EFCC know about this site or the CBN![]() |
Guy i'm encouraging u Look at a snippet 4rm my Project /* * File: Worker.h * Author: Kene * * Created on July 23, 2009, 3:59 PM */ #include <string> // program uses C++ standard string class #include <iostream>//uses c++ standard I/O functions #include "Keypad.h" #include "Controller.h" #include "Screen.h" #include "Define.h" using std::string; using std::cout; using std::endl; class Worker { public: Worker() { } void start()//starts the main worker { i=0; int del = DELAY; keypad.setCharacter('A'); screen.addToScreen(keypad); cout << "DELAY: "<< DELAY << endl; cout << "Worker Started"<< endl; cout << keypad.getCharacter()<< endl; //while(true) //{ //if(i>=100000) //{ // break; //} cout << i<< endl; //cout <<"Data Read: "<< controller.readInput()<< endl; cout <<"Pointer Address: "<< &keypad<< endl; screen.renderDigit(); mypad = &keypad; cout <<"Pointer Value: "<<mypad->getCharacter()<< endl; //i++; //} } private: Keypad keypad; Controller controller; Screen screen; int i; Keypad *mypad; }; Hope this one encourages u |
Data abstraction means hiding some data elements of a class from the public class Student { private String regNo; private String name; public void setRegno(String regNo) { this.regNo= regNo; } public String getRegno() { return regNo; } public void setName(String name) { this.name= name; } public String getName() { return name; } } Hoope this explains the concept |
/* * File: Worker.h * Author: Kene * * Created on July 23, 2009, 3:59 PM */ #include <string> // program uses C++ standard string class #include <iostream>//uses c++ standard I/O functions #include "Keypad.h" #include "Controller.h" #include "Screen.h" #include "Define.h" using std::string; using std::cout; using std::endl; class Worker { public: Worker() { } void start()//starts the main worker { i=0; int del = DELAY; keypad.setCharacter('A'); screen.addToScreen(keypad); cout << "DELAY: "<< DELAY << endl; cout << "Worker Started"<< endl; cout << keypad.getCharacter()<< endl; //while(true) //{ //if(i>=100000) //{ // break; //} cout << i<< endl; //cout <<"Data Read: "<< controller.readInput()<< endl; cout <<"Pointer Address: "<< &keypad<< endl; screen.renderDigit(); mypad = &keypad; cout <<"Pointer Value: "<<mypad->getCharacter()<< endl; //i++; //} } private: Keypad keypad; Controller controller; Screen screen; int i; Keypad *mypad; //struct itimerval it; }; I'm a C++ Developer call 08034275706 |
I'm also undergoing a research on Embedded System with C++.Email kcjojo8@gmail.com or call 08034275706 |
Do any body know how to read a Java webservice with nusoap?i've tried but its not working |
How are U am ok ![]() |
good post |
Man,U have to look first at what u have in mind, ur area of specialization, and ur ability to stick to problem solving procedures.C++ is good for general programming introduction but Java is gradually overtaking the market. Better still C/C++ is the still the mother of all!!! |
My babe betrayed my love for her after her promises, her phone went off and i could not see her for two months.Advice me |
C++ is good for drivers programming,but every solutin from C++ can also be solved by Java.Java is more good for the market |
Hurray my Bros for making Nigeria proud.Good lesson for upcoming stars like Mikel.He can still achieve that since he had made it in 2005 U-20 World Cup |
HttpSession session = request.getSession(); session.setAttribute("name","kencas" ;dats all |
For exporting to excel,u need a library to do it.Just call 08034275706.Will help u |
Handyx u line is not available.Better still call 08034275706 so we can talk |
Handyx, Which site to register?has the association been incorporated?i'm really Interested |
i agree with the last comment.C is the best language as far am concerned.Lets start from here.I don't know whether any researcher in Nigeria have delved into exclusive research like GENETIC PROGRAMMING,GENETIC ALGORITHM,embedded systems,Real-time Interfacing system etc.Lets work together.We have the skills here in Nigeria. |
Handyxinclude me in the list |
Lets kick off please.I have flare for enterprise systems.Please we could choose a date for the initial meeting.If possible i could lead. Consider this guys |
Hey Developers.Could any one elaborate more on MVC? |
1 2 (of 2 pages)
;
or the CBN
am ok 