Einfaches TCP Socketservertool in C



Hallo,

ich würde gerne einen Linux Shell Befehl "Warte auf Port X auf String Y"
haben. Das hier habe ich bisher:

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char** argv)
{

char* endp;
long port;

if (argc < 2)
{ printf("Zuwenig Argumente\n"); return 0; }

port = strtol(argv[1], &endp, 0);
if (*endp != 0)
{ printf("Ungültige Zahl: %s\n", endp); }

int server_socket, client_socket;
int laenge;
struct sockaddr_in serverinfo, clientinfo;
char empfangene_zeichen[100];
server_socket = socket(AF_INET, SOCK_STREAM, 0);
serverinfo.sin_family = AF_INET;
serverinfo.sin_addr.s_addr = inet_addr("83.125.32.203");
serverinfo.sin_port = htons(port);
laenge = sizeof(serverinfo);
bind(server_socket, &serverinfo, laenge);
printf("\n Der Server wartet...");
listen(server_socket, 3);



while(strcmp(empfangene_zeichen,"tanga\n") != 0)
{
client_socket = accept(server_socket, &clientinfo, &laenge);
read(client_socket,empfangene_zeichen,sizeof(empfangene_zeichen));
printf(empfangene_zeichen);

close(client_socket);
}


close(server_socket);
printf("\n Server beendet");
return 0;
}

Das funktioniert fast.
Aber:
Irgendwie funktioniert der Vergleich der empfangenen Zeichen mit dem String "tanga" nicht so wirklich. Woran könnte das liegen?

Vielen lieben Dank,

- Udo -
.



Relevant Pages

  • Using IIS 7 to relaying off Yahoo smtp server
    ... server: smtp.mail.yahoo.com. ... The following is the port number and the error message returned: ... System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String ... command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, ...
    (microsoft.public.inetserver.iis.smtp_nntp)
  • Using IIS 7 to relaying off Yahoo smtp server
    ... smtp outgoing mail server. ... The following is the port number and the error message returned: ... System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String ... String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, ...
    (microsoft.public.inetserver.iis.smtp_nntp)
  • Re: Using IIS 7 to relaying off Yahoo smtp server
    ... server: smtp.mail.yahoo.com. ... The following is the port number and the error message returned: ... System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String ... System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, ...
    (microsoft.public.inetserver.iis.smtp_nntp)
  • Jython socket typecasting problems
    ... I try to port a server application to Jython. ... Currently I do face problems with casting the string "localhost" to the ... This is the code section of my server class (I cut this from a Python ...
    (comp.lang.python)
  • RE: Some technical errors
    ... If the SMTP server is not running on port 25 TCP it is not a public ... Manager - Computer Assurance Services BDO Chartered Accountants & ...
    (Security-Basics)