PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Noms de domaine > comp.protocols.tcp-ip > udp client server test... Not working...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.protocols.tcp-ip TCP and IP network protocols.

udp client server test... Not working...

Réponse
 
LinkBack Outils de la discussion
Vieux 14/11/2006, 01h26   #1
SpreadTooThin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut udp client server test... Not working...

I'm having trouble with this class...
I don't seem to be transmitting or receiving data...
I want to try sending and receiving udp packets...
I have client and a server (so to speak)
the client send hello and then expects the receiver to echo it back.

updclient.cpp (Just general purpose UPD routines)

udpclient::udpclient(void)
{
sd = -1;
}

void udpclient::create(char *hostname, int portno)
{
if ((hp = gethostbyname(hostname)) == NULL)
{
addr.sin_addr.s_addr = inet_addr(hostname);
hp = gethostbyaddr((char *)&addr.sin_addr.s_addr,
sizeof(addr.sin_addr.s_addr), AF_INET);
}

printf("----UDPServer1 running at host NAME: %s\n", hp->h_name);

memcpy(&server.sin_addr, hp->h_addr, hp->h_length);

printf("(UDPServer1 INET ADDRESS is: %s )\n",
inet_ntoa(server.sin_addr));

/*** Construct name of socket to send to. ***/
server.sin_family = AF_INET;
server.sin_port = htons(portno);

/*** Create socket on which to send and receive ***/
sd = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sd < 0)
throw("Can't create socket.");
}

void udpclient::send(const char *buf, int n)
{
sendto(sd, buf, n, 0, (struct sockaddr *) &server, sizeof(server));
}

int udpclient::receive(char *rbuf, int rbufsize)
{
socklen_t fromlen = sizeof(from);
int rec = recvfrom(sd, rbuf, rbufsize, 0, (struct sockaddr *) &from,
&fromlen);
return(rec);
}
void udpclient::closeSock(void)
{
close(sd);
sd = -1;
}
udpclient::~udpclient()
{
if (sd != -1)
close(sd);
}

testclient.cpp
#include <iostream>
#include "udpclient.h"

int main (int argc, char * const argv[])
{
udpclient c;
char buffer[7];
c.create("192.168.1.100", 5000);
for (int i=0; i < 10; ++i)
{
c.send("hello", 6);
c.receive(buffer, 6);
}
c.closeSock();
}

testserver.cpp
#include <iostream>
#include "udpclient.h"

int main (int argc, char * const argv[])
{
udpclient c;
char buffer[7];
c.create("192.168.1.100", 5000);
for (int i=0; i < 10; ++i)
{
c.receive(buffer, 6);
c.send(buffer, 6);
}
c.closeSock();
}

  Réponse avec citation
Vieux 14/11/2006, 02h18   #2
Phil Frisbie, Jr.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: udp client server test... Not working...

SpreadTooThin wrote:
> I'm having trouble with this class...
> I don't seem to be transmitting or receiving data...
> I want to try sending and receiving udp packets...
> I have client and a server (so to speak)
> the client send hello and then expects the receiver to echo it back.


If there were any error checking in that code you could likely answer
your own question.

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com
  Réponse avec citation
Vieux 15/11/2006, 02h11   #3
SpreadTooThin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: udp client server test... Not working...


Phil Frisbie, Jr. wrote:
> SpreadTooThin wrote:
> > I'm having trouble with this class...
> > I don't seem to be transmitting or receiving data...
> > I want to try sending and receiving udp packets...
> > I have client and a server (so to speak)
> > the client send hello and then expects the receiver to echo it back.

>
> If there were any error checking in that code you could likely answer
> your own question.
>
> --
> Phil Frisbie, Jr.
> Hawk Software
> http://www.hawksoft.com


Shall I post the same code with error checking?

  Réponse avec citation
Vieux 15/11/2006, 04h59   #4
Phil Frisbie, Jr.
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: udp client server test... Not working...

SpreadTooThin wrote:

> Phil Frisbie, Jr. wrote:
>
>>SpreadTooThin wrote:
>>
>>>I'm having trouble with this class...
>>>I don't seem to be transmitting or receiving data...
>>>I want to try sending and receiving udp packets...
>>>I have client and a server (so to speak)
>>>the client send hello and then expects the receiver to echo it back.

>>
>>If there were any error checking in that code you could likely answer
>>your own question.

>
> Shall I post the same code with error checking?


No. You need to run the code with error checking and if you do not
understand the error code you get THEN post your source code AND the
error code.

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com
  Réponse avec citation
Vieux 15/11/2006, 15h02   #5
SpreadTooThin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: udp client server test... Not working...


Phil Frisbie, Jr. wrote:
> SpreadTooThin wrote:
>
> > Phil Frisbie, Jr. wrote:
> >
> >>SpreadTooThin wrote:
> >>
> >>>I'm having trouble with this class...
> >>>I don't seem to be transmitting or receiving data...
> >>>I want to try sending and receiving udp packets...
> >>>I have client and a server (so to speak)
> >>>the client send hello and then expects the receiver to echo it back.
> >>
> >>If there were any error checking in that code you could likely answer
> >>your own question.

> >
> > Shall I post the same code with error checking?

>
> No. You need to run the code with error checking and if you do not
> understand the error code you get THEN post your source code AND the
> error code.
>
>

I am not throwing any exceptions or errors...
I have ported the code to windows and am testing between
MAC OS X and windows.
Client and server work perfectly underwindows...
The udp server however is behaving oddly on mac os x.



--
> Phil Frisbie, Jr.
> Hawk Software
> http://www.hawksoft.com


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h26.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,23411 seconds with 13 queries