Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Shump

Pages: [1]
1
Network / Three general questions about networking in SFML
« on: January 20, 2009, 07:50:55 pm »
Ok, I think I'm getting the hang of it. To put it in a fewer words; you create a TCP and/or UDP, connect it to a server, and then let each socket handle both the sending and receiving messages, preferably in its own thread.

Although, what is the best way of sending and receiving messages simultaneously? Is it to set the sockets on non-blocking mode and let them switch between:
   checking if there is anything to send and send it.
and...
   checking if there is any messages to receive?

Or is it possible to copy an already connected socket and to let one of them send data, and the other (in another thread) receive data?

2
Network / Three general questions about networking in SFML
« on: January 20, 2009, 05:45:17 pm »
Quote from: "Tank"
I guess you've an error in your design. Clients normally don't listen on any ports for connections coming from a server. Just open the two ports (TCP and UDP) at the server. Then connect via TCP to the remote host and send an UDP packet to the server. When you're using a router to connect to the internet, it will take care of routing the UDP packets straight to your computer in case the server sends something back. This is called Network Address Translation (NAT).


Thanks alot for your answer! I realise that I've misunderstood a few things about the basic mechanics about sockets.

My client program consists of three threads and six sockets. The main thread handles keyboard inputs and sends messages to the server via one TCP socket or one UDP socket. The second thread has one listening TCP socket, constantly listening for new connections since I'm using a selector, and one socket handling incoming messages through the selector. The third thread works almost exactly in the same way as the second, although with UDP sockets rather than TCP.

If I got this right, while a TCP socket is connected to the server, is can be used both for sending and receiving messages, although not in the same time. Do I have to use two separate sockets, one sending and one receiving, connected to the same address and port?

It seems even more problematic with UDP sockets since it needs to be bound to a port, and (according to the SFML 1.3 tutorial) it is the same thing as listening to the port (written in parenthesis commented in the code).

3
Network / Three general questions about networking in SFML
« on: January 20, 2009, 11:52:29 am »
Hi!
I'm working on a simple multiplayer game, a school project. The game is based on the server-client model and it is using both TCP and UPD for different connections. I started out doing a simple chat-program, consisting of a server program and a client program, and the result was quite successful. I can start the server program on one computer, connect with several clients which can send and receive both TCP and UDP messages.

However, I've got some basic features that I would like to implement. Firstly, is it possible to have both a client program and a server program running on the same computer? I'm new to network coding, but I think it has to be something with the ports you use. At present, both my client and server program are using two ports, one for TCP listening and sending and one for UDP listening and sending. Maybe it is possible to achieve the wanted effect by using different ports for listening and sending, so that the send socket at the client program is using the same port as the listening socket at the server program and vice versa.

Secondly, in most network programs (e.g. multiplayer games) it is only necessary to open the ports for the server program, not the client. Although, when I tried my program over internet (I've previously only tested on LAN) I needed to open up ports for my client as well. HAs this something to do with the fact that I'm using a selector in the client program as well (which is not necessary, however, abit easier)?

Lastly, I'm also thinking of how to detect when a client is detected. It can be easily done by letting the disconnecting client send a "goodbye"-message and then the server can remove it from the list containing connected clients. However, if the client just cuts its connection with the server (e.g. it crashes) the connection will not be closed properly and I've experienced that the selector's timeout-function goes crazy and behaves as if it's set on a very short time (like 0.0...01 seconds). Is it possible to have the TCP socket nature of a constant connection to tackle this problem (which is the reason why I've been using it in the first plce)?

4
System / General questions about mutexes and threading
« on: December 31, 2008, 02:19:15 am »
I'm afraid I have to, unless I have got it completely wrong, since I'm using it to handle my network and it's necessary too have at least two threads; one for listening and one for sending.

Anyway, I think I'll just go for the easy "lock-whenever-I-need-to-wrote-or-read", because the only data-sharing I'll probably need is when the server get a new input from client and is sending it along the the rest of the program, which may not be too often, or at least not constantly.

5
System / General questions about mutexes and threading
« on: December 30, 2008, 09:58:11 pm »
Thanks a lot for your answer! However, it seems a bit paradoxical. Don't I get the same problem with the variables for how many threads there are waiting to read/write?

6
System / General questions about mutexes and threading
« on: December 27, 2008, 08:33:49 pm »
Hi! I've got two questions about SFML's threads and mutexes.

First, a general question about sharing variables and objects between threads. Is it necessary to use mutexes to lock an object both when you're reading and writing to it or is it enough just locking it when you write to it. In other words, what happens if a thread is reading an object, that is not locked, and then another thread wants to lock and write to it? It seems much more efficient to just lock it only when you need to change it, otherwise, the program may end up spending more time locking and unlocking an object just to get read and write access to it.

My second question is about functions(and methods as well) and threads. What happens if a thread wants to use a function at the same time as another? Is it necessary and possible to use mutexes to lock and unlock access to functions aswell?

7
Graphics / Create alpha mask from B/W image
« on: May 15, 2008, 10:57:08 pm »
So in other words, if I load an image that supports an alpha channel there's no need to create any alpha mask. That sounds OK to me (: Thanks!

8
Graphics / Create alpha mask from B/W image
« on: May 14, 2008, 01:31:01 pm »
Is it possible to create an alpha mask from a black and white image source? Does it have anything with sprite's blendmode to do?

Pages: [1]