Telefonino.net network
 
| HOMEPAGE | INDICE FORUM | REGOLAMENTO | ::. NEI PREFERITI .:: | RSS Forum | RSS News | NEWS web | NEWS software |
| PUBBLICITA' | | ARTICOLI | WIN XP | VISTA | WIN 7 | REGISTRI | SOFTWARE | MANUALI | RECENSIONI | LINUX | HUMOR | HARDWARE | DOWNLOAD | | CERCA nel FORUM » |

Torna indietro   WinTricks Forum > Software > Programmazione

Notices

Rispondi
 
Strumenti discussione
Vecchio 07-05-2004, 17.21.39   #16
P8257 WebMaster
Gold Member
 
Registrato: 07-01-2002
Loc.: Milano
Messaggi: 2.863
P8257 WebMaster promette bene
Quota:
NS-1 ha scritto:
web, 'malloc' non l'ho usato ma per il resto il codice ¨¨ ok, non sono un mago della programmazione ma in c me la cavo abbastanza...

secondo te, per esperienza magari, cosa potrebbe essere?

i caratteri non sono [[[[[[ ma ¨d¨d¨d¨d¨d¨d¨d¨d¨d
Nessuno mette in dubbio le tue capacità, sono cose che capitano.. senza codice comunque è difficile capire ... io penso che sia qualcosa che non pulisci, qualche buffer, qualcosa che rimane nel socket al momento della riconnessione... è difficile da dire, mi sono "incartato" moltissime volte in queste cose, per poi scoprire che erano banalità o sviste...

Bye

P.S.: A mio avviso il carattere restituito non ha alcuna importanza, è quello che personalmente definisco come "schifezza"
P8257 WebMaster non è collegato   Rispondi citando
Vecchio 07-05-2004, 17.52.39   #17
NS-1
Hero Member
 
L'avatar di NS-1
 
Registrato: 09-05-2002
Loc.: COMO
Messaggi: 1.135
NS-1 promette bene
... ma sai che questa svista proprio non la vedo e ci sto perdendo i capelli?
NS-1 non è collegato   Rispondi citando
Vecchio 07-05-2004, 18.03.38   #18
P8257 WebMaster
Gold Member
 
Registrato: 07-01-2002
Loc.: Milano
Messaggi: 2.863
P8257 WebMaster promette bene
Quota:
NS-1 ha scritto:
... ma sai che questa svista proprio non la vedo e ci sto perdendo i capelli?
Tipico .. .. altrimenti non sarebbe una svista..

Usa il debugger !

Bye
P8257 WebMaster non è collegato   Rispondi citando
Vecchio 07-05-2004, 21.44.28   #19
NS-1
Hero Member
 
L'avatar di NS-1
 
Registrato: 09-05-2002
Loc.: COMO
Messaggi: 1.135
NS-1 promette bene


se non ci riesco, posterò il codice


grazie
NS-1 non è collegato   Rispondi citando
Vecchio 10-05-2004, 00.03.11   #20
NS-1
Hero Member
 
L'avatar di NS-1
 
Registrato: 09-05-2002
Loc.: COMO
Messaggi: 1.135
NS-1 promette bene
sorgenti di prog fatti bene con tutti i controlli del caso?
NS-1 non è collegato   Rispondi citando
Vecchio 10-05-2004, 00.14.35   #21
pholcus
Linux Supporter
 
L'avatar di pholcus
 
Registrato: 02-12-2000
Loc.: Monza
Messaggi: 1.987
pholcus promette bene
Ne ho sicuramente da qualche parte, ma sono per linux/unix..
pholcus non è collegato   Rispondi citando
Vecchio 10-05-2004, 15.26.21   #22
NS-1
Hero Member
 
L'avatar di NS-1
 
Registrato: 09-05-2002
Loc.: COMO
Messaggi: 1.135
NS-1 promette bene
vanno bene cmq... devo solo comprendere "la logica" e cosa sbaglio nel disconnettere e riconnettere...

grazie...


NS-1 non è collegato   Rispondi citando
Vecchio 10-05-2004, 15.32.24   #23
NS-1
Hero Member
 
L'avatar di NS-1
 
Registrato: 09-05-2002
Loc.: COMO
Messaggi: 1.135
NS-1 promette bene
..questo è il mio server:

#include <stdio.h>
#include <winsock.h>
#include <vector>
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;


int PORT = 1978;
int MAX_CONNECT = 10;
bool bVal = true;


struct CLIENT_TYP {
bool InUse;
SOCKET ClientSocket;
struct sockaddr_in ClientAddr;
};


SOCKET lstSocket;
struct sockaddr_in saServer;

vector<CLIENT_TYP> Client;

int ClientsConnected = 0;
timeval timeout;

bool bLog = true;
bool bLogError = true;

////////////////////////////////////////////////////////

bool Error(char *error)
{
if (bLogError)
printf(error);
return true;
}

bool Log(char *log)
{
if (bLog)
printf(log);
return true;
}

////////////////////////////////////////////////////////

bool Setup()
{
int nRet;
WSADATA wsaData;

saServer.sin_family = AF_INET;
saServer.sin_addr.s_addr = INADDR_ANY;
saServer.sin_port = htons(PORT);

Log("\nInitializing Winsock...");
if (WSAStartup(MAKEWORD(1,1), &wsaData)) {
Log("FAILED\n");
Error("Error Initializing Winsock\n");
WSACleanup();
return false;
}
Log("OK\n");

Log("Creating Socket...");
lstSocket = socket(AF_INET, SOCK_STREAM, 0);
if (lstSocket == INVALID_SOCKET) {
Log("FAILED\n");
Error("Error Creating Socket\n");
WSACleanup();
return false;
}
Log("OK\n");

Log("Binding Socket...");
nRet = bind(lstSocket, (LPSOCKADDR)&saServer, sizeof(struct sockaddr));
if (nRet == SOCKET_ERROR) {
Log("FAILED\n");
Error("Error Binding Socket\n");
WSACleanup();
return false;
}
Log("OK\n");

Log("Setting up Listening...");
nRet = listen(lstSocket, SOMAXCONN);
if (nRet == SOCKET_ERROR) {
Log("FAILED\n");
Error("Error Listening\n");
WSACleanup();
return false;
}
Log("OK\n");

if (!Client.empty())
Client.clear();

Log("\n[ Server Set Up Successfull ]\n");
return true;
}

////////////////////////////////////////////////////////

int Disconnect(int Index)
{
closesocket(Client[Index].ClientSocket);
Client[Index].InUse = false;
ClientsConnected--;

return 1;
}

void Shutdown()
{
shutdown(lstSocket, 2);
for (int i = 0; i < Client.size(); i++)
Disconnect(i);
WSACleanup();
Log("[ Server Shut Down ]\n\n");
}

////////////////////////////////////////////////////////

int Check_Connections()
{
int nRet;
fd_set readfds;
int Client_Length;
CLIENT_TYP tmpClient;
Client_Length = sizeof(tmpClient.ClientAddr);

timeout.tv_sec = 0;
timeout.tv_usec = 0;

if (ClientsConnected < MAX_CONNECT)
{
FD_ZERO(&readfds);
FD_SET(lstSocket, &readfds);

nRet = select(lstSocket + 1, &readfds, NULL, NULL, &timeout);
if (nRet > 0) {
int clIndex = Client.size();
CLIENT_TYP newClient;
Client.push_back(newClient);

Client[clIndex].ClientSocket = accept(lstSocket, (struct sockaddr*)&Client[clIndex].ClientAddr, &Client_Length);
if (Client[clIndex].ClientSocket == INVALID_SOCKET) {
Log("\nAttempt to accept incoming connection failed");
return 1;
}
char *ClientIp = inet_ntoa(Client[clIndex].ClientAddr.sin_addr);
Log("\nNew connection made with: ");
Log(ClientIp);
Log("\n\n");
ClientsConnected++;
Client[clIndex].InUse = true;
}
}
return 1;
}

////////////////////////////////////////////////////////

void Get_Message(int clIndex)
{
int nRet;
char data[1000];

nRet = recv(Client[clIndex].ClientSocket, data, sizeof(data), 0);
char *ClientIp = inet_ntoa(Client[clIndex].ClientAddr.sin_addr);

if (nRet == 0) {
Log("\nClient has disconnected: "), Log(ClientIp), Log("\n");
Disconnect(clIndex);
}
else {

Log("<"), Log(ClientIp), Log("> ");
data[nRet] = '\0';

cout << data;


if(data[0] == '$' || data[0] == '+'){

shutdown(lstSocket, 0); // no ricezione
Disconnect(clIndex);

if(data[0] == '$')
WSACleanup();

Log("\n\nConnessione chiusa da: "), Log(ClientIp), Log("\n\n");


bVal = false;
}

else{
int index;

for(index = 0; index <= 999; index++){
if(data[index] == '\0'){

char buf2[10] = " --> OK\0";
char *bufPTR;

bufPTR = &data[index];

*strcat(bufPTR, buf2);

index = 1000;
}
}

send(Client[clIndex].ClientSocket, data,sizeof(data), 0);

Log("\n");

}

}
}

////////////////////////////////////////////////////////

void Check_Message()
{
int nRet;
fd_set msg_fds;
fd_set err_fds;
int nfds;

timeout.tv_sec = 0;
timeout.tv_usec = 0;

FD_ZERO(&msg_fds);
FD_ZERO(&err_fds);
nfds = 0;

for(int i = 0; i < Client.size() {
FD_SET(Client[i].ClientSocket, &msg_fds);
FD_SET(Client[i].ClientSocket, &err_fds);
nfds++;
i++;
}

nRet = select(nfds, &msg_fds, NULL, &err_fds, &timeout);

if (nRet > 0) {
for(int i = 0; i < Client.size(); i++) {

if (FD_ISSET(Client[i].ClientSocket, &err_fds)) {

char *ClientIp = inet_ntoa(Client[i].ClientAddr.sin_addr);
Log("\nClient has disconnected: "), Log(ClientIp), Log("\n");
Disconnect(i);
}

if (FD_ISSET(Client[i].ClientSocket, &msg_fds)) {
Get_Message(i);

}

}
}

}

////////////////////////////////////////////////////////

void main()
{

Setup();

while (bVal) {

Check_Connections();

Check_Message();

}

Shutdown();

system("PAUSE");
}


se non trovate errori posterò anche il client...

grazie
Ciao
NS-1 non è collegato   Rispondi citando
Vecchio 10-05-2004, 19.44.29   #24
NS-1
Hero Member
 
L'avatar di NS-1
 
Registrato: 09-05-2002
Loc.: COMO
Messaggi: 1.135
NS-1 promette bene
... fatto prove?

NS-1 non è collegato   Rispondi citando
Vecchio 10-05-2004, 19.55.55   #25
P8257 WebMaster
Gold Member
 
Registrato: 07-01-2002
Loc.: Milano
Messaggi: 2.863
P8257 WebMaster promette bene
Per quel che riguarda me .. l'ho letto .. stasera o domani mattina lo provo

Bye
P8257 WebMaster non è collegato   Rispondi citando
Vecchio 10-05-2004, 20.38.26   #26
NS-1
Hero Member
 
L'avatar di NS-1
 
Registrato: 09-05-2002
Loc.: COMO
Messaggi: 1.135
NS-1 promette bene
..grazie...
NS-1 non è collegato   Rispondi citando
Vecchio 12-05-2004, 15.03.38   #27
NS-1
Hero Member
 
L'avatar di NS-1
 
Registrato: 09-05-2002
Loc.: COMO
Messaggi: 1.135
NS-1 promette bene
... provato?
NS-1 non è collegato   Rispondi citando
Vecchio 13-05-2004, 18.56.39   #28
NS-1
Hero Member
 
L'avatar di NS-1
 
Registrato: 09-05-2002
Loc.: COMO
Messaggi: 1.135
NS-1 promette bene
?
NS-1 non è collegato   Rispondi citando
Vecchio 13-05-2004, 19.42.23   #29
LoryOne
Gold Member
WT Expert
 
Registrato: 09-01-2002
Loc.: None of your business
Messaggi: 5.505
LoryOne è un gioiello raroLoryOne è un gioiello raroLoryOne è un gioiello raro
Me lo sono copiato e compilato poco fa.
Mi faresti la cortesia di postare anche il client, per favore ?
LoryOne non è collegato   Rispondi citando
Vecchio 13-05-2004, 20.41.06   #30
NS-1
Hero Member
 
L'avatar di NS-1
 
Registrato: 09-05-2002
Loc.: COMO
Messaggi: 1.135
NS-1 promette bene
client:


#include <windows.h>

#include <sys/types.h>
#include <winsock.h>
#include <stdio.h>
#include <string.h>

#define PROTOPORT 1978
extern int errno;
char localhost[] = "localhost";

void main(argc, argv)
int argc;
char *argv[];
{
struct hostent *ptrh;
struct protoent *ptrp;
struct sockaddr_in sad;
int sd;
int port;
char *host;
int n=0;
char buf[1000];
char cDaInv=0;

#ifdef WIN32
WSADATA wsaData;
WSAStartup(0x0101, &wsaData);
#endif
memset((char *)&sad,0,sizeof(sad));
sad.sin_family = AF_INET;


if (argc > 2) {
port = atoi(argv[2]);
} else {
port = PROTOPORT;
}
if (port > 0)
sad.sin_port = htons((u_short)port);
else {
fprintf(stderr,"Bad Port Number %s\n",argv[2]);
exit(1);
}



if (argc > 1) {
host = argv[1];
} else {
host = localhost;
}



ptrh = gethostbyname(host);
if ( ((char *)ptrh) == NULL ) {
fprintf(stderr,"Invalid Host: %s\n", host);
exit(1);
}
memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length);



if ( ((int)(ptrp = getprotobyname("tcp"))) == 0) {
fprintf(stderr, "Cannot map \"tcp\" to protocol number");
exit(1);
}


sd = socket(PF_INET, SOCK_STREAM, ptrp->p_proto);
if (sd < 0) {
fprintf(stderr, "Socket Creation Failed\n");
exit(1);
}



if (connect(sd, (struct sockaddr *)&sad, sizeof(sad)) < 0) {
fprintf(stderr,"Connect Failed\n");
exit(1);
}




printf("\n\n DCN-Server\n\t+ Termina questo programma\n\t$ Termina anche il client\n\n - Connessione Stabilita\n");
//ECHO



do{

printf("\nINVIA: ");
gets(buf);

if(buf[0] != '+'){

send(sd,buf,strlen(buf),0);
n = recv(sd, buf, sizeof(buf), 0);
printf("%s\n",buf);
}
else
n = 0;


}while (n > 0);

closesocket(sd);

printf("\nConnessione Conclusa, Client %s\n\n", buf[0] == '+' ? "ancora attivo" : "disattivato");


system("PAUSE");
exit(0);
}
NS-1 non è collegato   Rispondi citando
Rispondi


Utenti attualmente attivi che stanno leggendo questa discussione: 1 (0 utenti e 1 ospiti)
 
Strumenti discussione

Regole di scrittura
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is ON
Gli smilies sono ON
[IMG] è ON
Il codice HTML è OFF

Vai al forum

Discussioni simili
Discussione Autore discussione Forum Risposte Ultimo messaggio
[MDV] 2006 - problema kde juggler Linux e altri Sistemi Operativi 4 29-12-2006 21.06.08
[XP/SP2] Controllo in corso del file System primoair Windows 7/Vista/XP/ 2003 2 28-02-2006 22.13.01
[Valutazione] cpu+mobo+ram+scsi+sata+video Don`t`Ask Mercatino Usato 2 14-11-2004 18.54.06
controllo D:/ al boot slivio... Windows 7/Vista/XP/ 2003 2 21-11-2003 01.32.59

Orario GMT +2. Ora sono le: 12.13.30.


E' vietata la riproduzione, anche solo in parte, di contenuti e grafica.
Copyright © 1999-2017 Edizioni Master S.p.A. p.iva: 02105820787 • Tutti i diritti sono riservati
L'editore NON si assume nessuna responsabilità dei contenuti pubblicati sul forum in quanto redatti direttamente dagli utenti.
Questi ultimi sono responsabili dei contenuti da loro riportati nelle discussioni del forum
Powered by vBulletin - 2010 Copyright © Jelsoft Enterprises Limited.