| Witam,
jak pisalem w dziale c/c++ pisze na projekt server SMTP, ale napotkalem na problem gdyz, serwer nie odbiera komunikatu "220" jako server ready, tylko ciagle czeka nie wiem na co ;/ a po chwili mi w programie the bat (nim testuje) wyskakuje server not ready. probowalem napisac to w C jak rowniez w JAVIE z tym samym komunikatem bledu ;/
tu jest kod w C
[c]
int main() {
if ( WSAStartup( MAKEWORD(2,0), &wsaData ) !=0 ){
printf("Blad wsastartup");
system("pause");
exit;
}
Hostent=gethostbyname(buf);
if ( Hostent == NULL) {
printf("Blad gethostbyname");
system("pause");
exit;
}
printf(" IP Address : %s\n", inet_ntoa(*((struct in_addr *)Hostent->h_addr)));
////// mam moj adres IP
//////// ja modyfikuje
int sockfd, new_fd; // nasłuchuj na sockfd, nowe połaczenia na new_fd
struct sockaddr_in my_addr; // informacja o moim adresie
struct sockaddr_in their_addr; // informacja o adresie osoby łączącej się
int numbytes;
int sin_size;
char test[]={2,2,0};
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
printf("socket");
getchar();
exit(1);
}
my_addr.sin_family = AF_INET; // host byte order
my_addr.sin_port = htons(25); // short, network byte order
my_addr.sin_addr.s_addr = INADDR_ANY; // uzupełnij moim adresem IP
memset(&(my_addr.sin_zero), '\0', 8); // wyzeruj resztę struktury
if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr))
== -1) {
printf("bind");
getchar();
exit(1);
}
if (listen(sockfd, BACKLOG) == -1) {
printf("listen");
getchar();
exit(1);
}
printf("czekam\n");
sin_size = sizeof(struct sockaddr_in);
if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr,
&sin_size)) == -1) {
printf("accept");
getchar();
}
printf("polaczyl sie z: %s\n",inet_ntoa(their_addr.sin_addr));
if (send(new_fd, "220 enterprise Sendmail 5.64/zippy-1.22.01 ready at Mon, 25 Jun 97 09:34:12 -0400 (GMT)\n",89,0) == -1){
printf("send");
getchar();
}
if ((numbytes=recv(new_fd, buf, MAXDATASIZE-1, 0)) == -1) {
printf("recv");
getchar();
exit(1);
}
buf[numbytes] = '\0';
printf("Received: %s\n",buf);
[/c]
dodam ze do slow Received NIGDY nie dochodzi, zawsze sie wysypie na wysylaniu, a tutaj jest kod w JAVIE
[java]public class Server1 {
private ObjectInputStream wejscie;
private ServerSocket Server;
private ObjectOutputStream wyjscie;
private Socket[] klient = new Socket[2];
private int licznik=0,punkty1,punkty2,odkryj=33,aktualnieGra,koniec,drugiGracz,odpowiedź;
private String liczby = new String();
private Server1(){
try {
System.out.println("odpalam serwer");
this.Server = new ServerSocket(25);
klient[0] = Server.accept();
System.out.println("podpinam usera 1");
System.out.println("informacje o osobie : " + klient );
PrintWriter out = new PrintWriter(klient[0].getOutputStream());
out.println("220");
do{
}while (koniec==0);
} catch (IOException e) {
e.printStackTrace();}
}[/java]
prosze o pomoc w znalezieniu bledu, czemu nie chce mi sie to odebrac w programie pocztowy, a moze wina lezy w tym ze mam firewalla? ale to raczej malo prawdopodobne bo polaczenie serwer<->klient dziala... nie dziala prawidlowo wysylanie :(
|