Sign in to follow this  
campbellec

What to use?

Recommended Posts

You could try creating a UDPListener. Not sure if there actually is such a class, but there should be something like it, cos there is a TcpListener class already. If there is a UdpListener class, you'll find info about it by googling.

Edit: Clicky

[Edited by - Afr0m@n on March 6, 2006 3:57:58 PM]

Share this post


Link to post
Share on other sites
There is no such thing as UDP listener.
A 'UDP listener' is a UDP socket that receives.
Here is a sample of echo server


struct sockaddr_in __remote_sin;
int _sock;
if((_sock = ::socket(AF_INET, SOCK_DGRAM, 0))==-1){
return WSAGetLastError();
}
::memset(&_local_sin, 0, sizeof(_local_sin));
_local_sin.sin_family = AF_INET;
_local_sin.sin_addr.s_addr = ::htonl(INADDR_ANY);
_local_sin.sin_port = ::htons(port/*1-32768*/);
if(-1 == ::bind(_sock,(struct sockaddr *)&_local_sin, sizeof(_local_sin)))
return WSAGetLastError();

memset(&_remote_sin,0,sizeof(_remote_sin));
int iRecvLen = sizeof(_remote_sin);
unsigned char buff[1280]={0};
int length = (int)recvfrom (_sock, (char*)buff, 1280,
0,
(struct sockaddr *) &_remote_sin,
&iRecvLen);
::sendto(_sock, (char*)buff, length, 0, (struct sockaddr *) &_remote_sin,sizeof (_remote_sin)) ;


Share this post


Link to post
Share on other sites
There is no such thing as UdpListener, no - but there is such a thing as a UdpClient in C#. What you posted is C code, and very bad C code at that (as far as readability goes). Just fixed my link - check it up!

Share this post


Link to post
Share on other sites
Just learn to use UDP or TCP/IP.
This will start a flame war, but I'll strike first:

TCP/IP is good for setting stuff up (and may be fine for anything that does not require lag < 100ms).
UDP is good for quick action games. FPS's or 2D fighters or something. You will probably want to go ahead and learn UDP because it can do things TCP/IP can't and its a bit quicker for the most part.

Share this post


Link to post
Share on other sites
For action, UDP is probably better. For guaranteed arrival of data, which is very convenient, TCP is better. So it depends how important the 'action' part of your game is.

If you're writing in C#, look at the documentation for the Socket class, and for your server the TcpListener/UdpListener classes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Afr0m@n
There is no such thing as UdpListener, no - but there is such a thing as a UdpClient in C#. What you posted is C code, and very bad C code at that (as far as readability goes). Just fixed my link - check it up!


You can wrap anything in a C# class and call it UDP Client.
Actually there is no such thing as C#, just a ridiculous
microsoft invention. Great languageas are made by people
not by corporations.

Share this post


Link to post
Share on other sites
I'm not the world's biggest Microsoft fan myself, but of all the valid accusations that can be levelled at them, I don't think "you don't employ people" is one of them. Anders Hejlsberg invented C# for Microsoft, Dennis Ritchie invented C for AT&T. Same sort of thing. Now let's remember the original posted clearly mentioned C# in his post, and post further responses with that in mind?

Share this post


Link to post
Share on other sites
Quote:
Original post by campbellec
For an action/rpg game in C#/MDX, directplay, winsock, or another?


I'm too lazy to put this into proper English...

  • DirectPlay has been deprecated for some time now; don't use this.
  • Use Asychronous Sockets; google this, but don't worry if you have troubles with the tutorials, just post here when you get confused and someone will help you.
  • TCP/UDP Listener wrappers arn't for MORPG!
  • Use TCP protocal; UDP is poisoned ice-cream.

    Quote:
    Original post by Afr0m@n
    There is no such thing as UdpListener, no - but there is such a thing as a UdpClient in C#. What you posted is C code, and very bad C code at that (as far as readability goes). Just fixed my link - check it up!


    That is not C code.

    Share this post


    Link to post
    Share on other sites
    Quote:
    Original post by Thevenin
    That is not C code.


    The only clue that it's C++ is the fact that you scope the library function calls with the global scope operator. I think Afr0m@n's point is still valid: the guy asked for C#; your code doesn't really help in this case.

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    Sign in to follow this