Bitte helfen Softwarepraktikumsaufgabe: Serverprogrammierung (client) am beispiel an zahlenraten
-
ne, geht nicht.
du wirst dich selber bemühen müssen, einen ansatz zu finden.
dann kannst du fragen, wenn du nicht weiterkommst.oder stell es gegen geld ins projekteforum.
-
-
Ansonsten sind die "Socket Tipps" auf zotteljedi.de sehr empfehlenswert.
-
ich habe alles fertig es fehlt nur das ratespielprogramm wie in der AufgaBE BESCHRIEBN . dIES ist die main funktion .Kann jemand mir ein gutes QUELLCODE SCHICKEN für das Zahlenmratenspiel zwichen client und server damit ich es einbauen kann bitteeeeeeeeeee!
/**********************************************************************
**
** This module implements the communication between a client and an
** echo server.
**
***********************************************************************
**
** FILENAME:
** main.c
**
** CONTAINED FUNCTIONS:
** handleCommunication()
** - this function implements the communication between client and
** server
**
** main()
** - the main function
**
**
**
**
**
**
**
**********************************************************************//********* include files *********************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>#ifdef _WIN32
#include <winsock.h>
#else
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif#include "netutils.h"
#include "logging.h"/********* private constants ****************************************/
#define ECHO_DEFAULT_PORT 7342 / default port number for echo */#define BUFFER_SIZE 1024 /* max size of messages */
/********* private types *********************************************/
/* NONE *//********* public global variables (as extern in header file) ********/
/* NONE *//********* private global variables **********************************/
/* NONE *//******** private functions *****************************************/
bool handleCommunication(int sock);/**********************************************************************
** main
**
** This function implements the main function.
**
** PARAMETERS
** argc number of parameters given to the executable
** argv array of strings containing all parameters
**
** RETURN VALUE
** The return value should be 0 (EXIT_SUCCESS) if all things went
** well. Otherwise the function returns a value other than 0 (EXIT_FAILURE).
**
** SIDE EFFECTS
** none
**
**********************************************************************/
int
main(int argc, char *argv[])
{
char *serverName; /* name of the server */int sock; /* file descriptor for client socket /
short port = ECHO_DEFAULT_PORT; / port number */dtrace("entering main()");
/* check the parameters */
if (argc < 3) {
derror1("usage: %s <echo-server> [<port-number>]", argv[0]);
dtrace("leaving main() with exit status");
return (EXIT_FAILURE);
}/* give alias names to the parameters */
serverName = argv[1];
if (argc > 3) {
port = atoi(argv[3]);
}/* start the socket session */
if (!startSocketSession()) {
derror("startSocketSession() failed!");
dtrace("leaving main() with exit status");
return (EXIT_FAILURE);
}/* create a new socket and connect the socket to the given service */
if (SOCKET_ERROR == (sock = createClientSocket(serverName, NULL, port))) {
derror("socket creation failed!");
stopSocketSession();
dtrace("leaving main() with exit status");
return (EXIT_FAILURE);
}/* Verbindung zum Client ist aufgebaut*/
/* handle the communication between the client and the server */
if (false == handleCommunication(sock)) {
derror1("communication with %s failed!", serverName);
stopSocketSession();
dtrace("leaving main() with exit status");
return (EXIT_FAILURE);
}/* all things are done, so shutdown the connection /
if (!shutdownAndCloseSocket(sock)) / Socket freigeben /{
derror("shutdown and close socket failed!");
stopSocketSession();/ API beenden*/
dtrace("leaving main() with exit status");
return (EXIT_FAILURE);
}/* stop the socket session */
stopSocketSession();dtrace("leaving main()");
return (EXIT_SUCCESS);
}
/******** end of function main ***************************************//**********************************************************************
** handleCommunication
**
** This function implements the main communication between the client
** and the server. The client transmits all data lines from the file
** given by parameter fileName and sends the lines via the socket sock
** to the server. The socket is connected to the echo service, so the
** same message should be sent back to the client.
**
** PARAMETERS
** sock handle to a socket connected to an echo service
** fileName name of a data file which is sent to the server
**
** RETURN VALUE
** The return value should be true if all things went well.
** Otherwise the function returns false.
**
** SIDE EFFECTS
** All data lines in the file fileName are sent to an echo service.
**
*********************************************************************/
bool
handleCommunication(int sock )
{
char msg[BUFFER_SIZE]; / buffer for reading from file /
char buf[BUFFER_SIZE]; / buffer for reading from socket /
int msgLength; / length of a message /
bool finished = false; / control the main while loop */
FILE *file; /* handle for data file */unsigned short nummer=50;
unsigned short nummer2=htons(nummer);dtrace("entering handleCommunication()");
sendMessage(sock,(char*)&nummer2,sizeof(nummer2));
receiveMessage(sock,buf,1);
printf("\n\n%s\n\n",buf);
dtrace("leaving handleCommunication()");
return (true);
}
/******** end of function handleCommunication ************************//******** end of file main.c *****************************************/
-
Du wirst doch wohl so ein Ratespiel programmieren können O_o Denk 5 Minuten drüber nach, was passieren muss und das codest du dann nach ..
-
hallo romeo
achtung: wegen sowas habe ich mal 0 punkte gegeben.
http://www.kaskus.com/archive/index.php/t-108961.htmldeine profs/lehrer sind sicher net ganz .. naiv.
ändere zumindest ein paar namen, alle kommentare selber schreiben.. etc.
-
@elise: War ja wohl klar, dass man ohne ein Zahlenraten zu schaffen das Wort "Side Effects" in seine Kommentare einbaut ist äußerst selten
MfG SideWinder
-
Hab ich das jetzt richtig verstanden, dass du nicht weißt, wie du das Erraten gestallten sollst?
Die verbreiteste Methode ist da sicherlich die Binärsuche:
a) Du setzt 0 als rechten Rand (rR) und 10000 als linken Rand (lR).
b) nimmst die Halfte deines Bereichs h=(lR-rR)/2.
c) Fragst ob h die Zahl ist, wenn ja bist du fertig.
d) Wenn nicht fragsr du ob die Zahl kleiner/größer als die Zahl ist.
e) Ist die Zahl größer als h setzt du rR=h. Ist die Zahl größer als h setzt du lR=h. Dann wiederholst du alles ab b)Ist echt nicht schwer sowas zu programmieren.
-
inhotemp Die main.c datei darf ich aus dem tuturial so übernehmen,das was ich will ist ,in den bool handle kommunikation abschnitt das eingentliche programm aufzuschreiben. d.h ein zahlenratespiel zwischen dem client und server wenn du mir deine lösung schiken könntest wäre nett.
-
imhotep hat dir schon eine quasi fertige Lösung gegeben, nämlich die Abläufe des Algorithmus zum Zahlen finden!
Du musst das nur noch in C umsetzen und naja, das ist doch sehr verständlich gemacht von ihm!