Sign in to follow this  

simple networking

This topic is 4732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been away for abit, but now I'm back and thinking of a new project. I was thinking of trying to do something multiplayer. my first idea, is to have a text file on one computer, and another computer be able to add/read lines from this file. If you have asny good tutorials on this matter, please post them

Share this post


Link to post
Share on other sites
There's also OpenTNL which is the networking part of the torque engine released under the GPL. If you use this you can have a decent networking library and concentrate on your game rather than trying to get networking code working.

Share this post


Link to post
Share on other sites
Id perfer to learn the code, no real reason, I just like to know what Im doing.

The beej tut isn't too usefull, as he is programming in unix, rather than windows, but I found another one at http://www.frostbytes.com/~jimf/papers/sockets/winsock.html

I have code for both a client and a server now: the server sets up and then uses the accept command to wait for a connection from the client. I then run the client program, which connects to the server (I think it does anyway) and tries to send some data. I get no errors, but the server program doesn't seem to respond or run the next line of code, MessageBox(...).

What I need is some source code, for both the client and the server, that uses the:

listen
accept
connect
socket

commands, If any one has some good code, please post it up.

Share this post


Link to post
Share on other sites
Quote:
Original post by crazy_andy
The beej tut isn't too usefull, as he is programming in unix
It's largely the same.
Quote:
Original post by crazy_andy
What I need is some source code, for both the client and the server, that uses the:

listen
accept
connect
socket

commands, If any one has some good code, please post it up.
Which language? C++?

Share this post


Link to post
Share on other sites
I found my problem, the accept function:

new_sock = accept(s,NULL,NUL);

The problem is that the code gets to this line and doesn't continue. from several sources I have found people saying that the function will wait for a connection for a couple of seconds and then will return an error if there has not been one recieved. However my code just stops on this line.

anyone have any ideas what is goin on.

Share this post


Link to post
Share on other sites
Ok, I have found loads of examples using the same code as me, which seem to work, but mine still doesn't work.

On msdn it says the server requires NT or Windows server something. Does that mean I can't use the commands: accept, listen ... when having two computers connect, both on XP.

Also what type of app should it be, console, win32, win32 console ...

I really appreciate all the responses I have allready recieved, and any I get, because I have never worked with networking before.

Share this post


Link to post
Share on other sites
sense you are using the accept function i'm assuming your making a server... so it's time for you to learn how to use multithreading.. that's probably the best way to do it.

As for your answer, it waits on the accept function until someone tries to connect.

I found these two great tutorials, which taught me everything i needed to know:
This one
and this one

Sorry if that's not exactly what your looking for, still a little too tired to be doing this this early [grin]

Hope that helps
~zix~


Edit: I was looking at those tutorials again, and i noticed i used _beginthread(function, NULL); instead of AFXBeginThread(), just so you know. Have to include process.h if you use my way though.

Edit2: I use a console, but it can be a win32 application... and i use commands both listen and accept, as you can probably see by the tutorials.

Share this post


Link to post
Share on other sites
OK, Ive made a server, following the tut, and it seems to work, however when its running, Im getting a connection from 204.204.204.204 constantly. Im using a wireless router, which it could be, but Im not sure. If it is then what can I do about it?

Share this post


Link to post
Share on other sites
I was looking around and found this thread, and he had the same problem you did.
Thread here Google is very useful you know.

If you are having the same problem he was, it's simply a problem with the accept..
Quote:

Thanks. It was a problem @ accept(); I had to put the last param.

ret = sizeof(struct sockaddr);
sckClient = accept(sckListen,(LPSOCKADDR)&clientN,&ret);


Hope i could be of help
~zix~

Share this post


Link to post
Share on other sites

This topic is 4732 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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