|
Hi there,
I've made the Tic Tac Toe game.
Now I also added the "Multiplayer" function (LAN - TCP - UDP).
My problem is after I created the Multiplayer menutoolstrip and the dialog for the connection, I have some problems to link it up to the game.
Here is my code:
[code]
namespace TicTacToe
{
public partial class Multiplayer : Form
{
Socket sck;
EndPoint epLocal, epRemote;
public Multiplayer()
{
InitializeComponent();
sck = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
sck.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
textLocalIp.Text = GetLocalIP();
textFriendsIp.Text = GetLocalIP();
}
private void buttonStart_Click(object sender, EventArgs e)
{
try
{
epLocal = new IPEndPoint(IPAddress.Parse(textLocalIp.Text), Convert.ToInt32(textLocalPort.Text));
sck.Bind(epLocal);
epRemote = new IPEndPoint(IPAddress.Parse(textFriendsIp.Text), Convert.ToInt32(textFriendsPort.Text));
sck.Connect(epRemote);
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
buttonStart.Text = "Connected";
buttonStart.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private string GetLocalIP()
{
IPHostEntry host;
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
return "127.0.0.1";
}
private void MessageCallBack(IAsyncResult aResult)
{
try
{
int size = sck.EndReceiveFrom(aResult, ref epRemote);
if (size > 0)
{
byte[] receivedData = new byte[1464];
receivedData = (byte[])aResult.AsyncState;
}
byte[] buffer = new byte[1500];
sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer);
}
catch (Exception exp)
{
MessageBox.Show(exp.ToString());
}
}
}
}
[/code]
Stuck at combining the Multiplayer.cs to the Mainform.cs (The main game)..
Any tip or ideas for letting me continue my work will be appreciated.
Thanks.
|
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using System.Web.Http;
using System.Data;
using System.Data.SqlClient;
namespace Fabco_WebApi.Controllers
{
public class DownloadPDFController : ApiController
{
public static string ConnectionString = Convert.ToString(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
FabcoDBDataContext _ObjDb = new FabcoDBDataContext(ConnectionString);
[HttpGet]
public HttpResponseMessage Get()
{
string[] FN = Directory.GetFiles(@"C:\XXX");
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
string query = "select * from XXX where convert(datetime,convert(varchar(10),last_update,101))=convert(datetime,convert(varchar(10),'2015-03-19',101))";
SqlCommand Command = new SqlCommand(query, connection);
SqlDataAdapter da = new SqlDataAdapter(Command);
DataSet ds = new DataSet();
da.Fill(ds);
while (true)
{
if (ds.Tables[0].Rows.Count > 0)
{
MemoryStream responseStream = new MemoryStream();
bool fullContent = true;
var fName = string.Empty;
for (int i = 0; i <=ds.Tables[0].Rows.Count; i++)
{
fName = ds.Tables[0].Rows[i][1].ToString();
var DataFlag = ds.Tables[0].Rows[i][7].ToString();
string aa = "C:\\Fabco";
//string fName = "jQueryNotes.pdf";
var filepath = aa + "/" + fName;
//MemoryStream responseStream = new MemoryStream();
Stream fileStream = File.Open(filepath, FileMode.Open);
//bool fullContent = true;
fileStream.CopyTo(responseStream);
fileStream.Flush();
fileStream.Close();
}
responseStream.Position = 0;
HttpResponseMessage response = new HttpResponseMessage();
response.StatusCode = fullContent ? HttpStatusCode.OK : HttpStatusCode.PartialContent;
response.Content = new StreamContent(responseStream);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = fName.ToString() };
return response;
}
}
}
}
}
|
|
|
|
|
A single response can only return a single file. If you want to return multiple files, you will need to combine them in a zip file. DotNetZip[^] would probably be a good place to start.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If you want two separate downloads you'll need to make two requests. One technique for doing this is to show the user a page that has two hidden iframes and the src of the iframe is the url of your page that pushes the file to the user.
|
|
|
|
|
Some of programming SDK have some methods what are in draft status or with some bugs. For example 50% of requests hangs up.
How to create some kind of "time exeption" if internet request hangs up or sometimes hangs up.And redo it until success.
About about = service.About.Get().Execute();
ps Analog Delphi IdAntiFreeze. try{} doesn't help.
modified 20-Mar-15 5:45am.
|
|
|
|
|
You could either set a timer to see if server responds in a particular time, or use a try { } catch { } block to manage anything that happens unexpectedly.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
|
Hello there. I am trying to implement tree node mouse double click event along with context menu strip. Problem is: I have to click three times, in order to get the functionality of node double click. Skeleton of the program is as follows
private void tree_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
}
private void tree_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
}
}
What should be done here.... so that I don't have to click three times for the NodeMouseDoubleClick event. Thanks for any input.
modified 20-Mar-15 6:19am.
|
|
|
|
|
Double-clicking on a node means "expand" or "collapse". It then calls those events[^].
You'd have to work against the system to prevent that default-working, as explained on SO here[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I am developing an outlook ad-in application.
I am able to build the solution but not able to generate .VSTO and .manifest file.
So i am not able to register the addin.
I am using following development environemnt
VS2010 sp1
outlook 32 bit
windows 2008 server 64 bit OS
Can you please let me know where I need to change or some settings need to be changed?
Thanks,
SMA
|
|
|
|
|
What does "cannot build the solution" mean? Does it show a compiler error? What article did you use to build your prototype?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
My .Net application has registered with a particular table using SQLDependency for change events . Once the table content is changed, .Net application should be notified.
This happens correctly except on Hyper V machines.
Also, for this issue to happen, "Use sharing Wizard" option should be checked in "View" tab of "Organize\Folder Options" in Windows Explorer
Further Diagnostics:
I checked the broker Service and is enabled.
Also, the sys.transmission_queue table which contains any error message in case messages are not delivered is empty.
Any suggestion in this regard would be appreciated.
Thanks in advance.
Regards,
Rakesh Kumar Sah
|
|
|
|
|
Hello,
I'm running an exe application in my C# form app. I need to get the data from the exe application and save it on a database in my c# app. How is it possible? Please help.
|
|
|
|
|
That isn't a question we can answer: it depends on the application that you are running as the EXE file.
Since we have no idea what that is, or what data it deals with, how it stores it, or anything else about it we can't even begin to help you.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It's a university project. The exe application is a calender planner. Whenever a new task is added to a specified date, it is updated in the database where sorting is done. If ever the date and time is already booked, a warning message is given.
|
|
|
|
|
That doesn't really help.
It's like calling the garage and asking then to fix your car, and telling them nothing except "it's a Ford".
Think about it: what do you know about the app, in detail. Remember, we can't see you your screen, or access your HDD... or read your mind!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Someone just pointed out about the security risks. I thought it would be wise to use the exe app. I'll just try to write my own calender planner and get data directly then. Thank you
|
|
|
|
|
Well, you're not really going to get the data out of the running application itself. It'd be far easier to get it from whatever storage the application is saving it's data to.
|
|
|
|
|
Member 11336027 wrote: I need to get the data from the exe application and save it on a database in my
c# app. What university?
Saving that data should be done from the original application, not an external one. Doing it from an external app would also introduce security-risks. So, simply change the source-code of the original application.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I thought it will be wise to use an exe app, didn't think about the security risks. I'll try to write my own calendar planner and get data directly.
|
|
|
|
|
Try to access exe application database directly with your application if any update done in third party application database it should update your application that's it
|
|
|
|
|
How to Remove Default Column indicating cursor position in Datagridview in C#.
I'm getting data in datatable from SQL Server
|
|
|
|
|
If you mean the column on the LHS, then just set the RowHeadersVisible property[^] to false
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
With all the open web libraries out there... we find that we can create some very nice MVC projects (quickly) using them! WPF is my personal favorite Desktop framework but sometimes I find myself wishing I could use some of the open source web stuff in the WPF projects.
Conceptually if a WPF project could easily bypass IIS but provide similar web services (gets and posts) then we know that MVC would be happy as it doesn't care who does the service. Assume now that we could use the controller model of MVC inside of a WPF project, host a browser and use ViewModels just like we do today in WPF. The project template would then look very similar to the MVC template but would be for desktop applications. We could easily combine WPF controls with the WebBrowser or many instances of the web browser (one for each control) and use the Controller model on them for the post backs.
The first hurdle would be bypassing IIS and containing the equivalent HTTP support in a WPF project.... The second would be how to implement the controller base class as we know from MVC that it is a pretty intense component. Of course they always say start simple right?
Thoughts? Or am I just going crazy?
|
|
|
|