d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Error While Using Tftp Read/write From 2 Pc
12Next
Add Reply New Topic New Poll
Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Apr 2 2014 05:27pm
I tested this code and worked fine with my laptop (host). So, I tried to run my laptop as host and get file with my desktop but always get a timeout error.

here is the code:

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using System.IO;

namespace TFTP_Server
{
class CRRQ
{
EndPoint m_PointDistantRRQ;
string m_strFichierRRQ;

public void SetPointDistant(EndPoint PointDistant)
{
m_PointDistantRRQ = PointDistant;
}

public void SetFichier(string NomFichier)
{
m_strFichierRRQ = NomFichier;
}

public void MonThreadRRQ()
{
Socket socket;
EndPoint PointLocal = new IPEndPoint(0,0);
FileStream m_fs;
int nTimeout = 0;
int NbNack =0;
int test = 0; //
bool bRead;
int nOctetsLu;
int NBloc = 0;
byte[] bTrame;
byte[] bNack = { 0,5, 0, 0 };
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.Bind(PointLocal);

if (!File.Exists(m_strFichierRRQ))
{
socket.SendTo(bNack, 4, SocketFlags.None, m_PointDistantRRQ);
return;
}

m_fs = File.Open(m_strFichierRRQ, FileMode.Open, FileAccess.Read, FileShare.Read);


do
{
bTrame = new byte[516];
nOctetsLu = m_fs.Read(bTrame, 4, 512);
NBloc++;
if (NBloc > 65535)
NBloc = 0;
byte[] bNBock = new byte[] { (byte)(NBloc >> 8), (byte)(NBloc & 0xFF) };
bTrame[0] = 0;
bTrame[1] = 3;
bTrame[2] = bNBock[0];
bTrame[3] = bNBock[1];
do
{
socket.SendTo(bTrame, nOctetsLu+4, SocketFlags.None, m_PointDistantRRQ);
bRead = socket.Poll(5000000, SelectMode.SelectRead);
if (!bRead) [COLOR=green]//I'm stuck at this[/COLOR]
nTimeout++; [COLOR=green]//timeout using my desktop[/COLOR]
else
{
socket.ReceiveFrom(bTrame, ref m_PointDistantRRQ);
if (bTrame[0] != 0 && bTrame[1] != 4)
NbNack++;
}
}
while (bRead == false && nTimeout < 10 && NbNack < 3);

}
while (nOctetsLu == 512 && nTimeout < 10 && NbNack < 3);
if (NbNack == 3)
socket.SendTo(bNack, 4, SocketFlags.None, m_PointDistantRRQ);
test = bTrame[3];
m_fs.Close();
socket.Close();
}
}
}
Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Apr 2 2014 05:31pm
could this be a router problem? or windows firewall

This post was edited by eric838 on Apr 2 2014 05:39pm
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Apr 2 2014 05:42pm
Not familiar with this language but are you specifying the port # when opening your sockets?

e/ If so, make sure the port is open on your router

This post was edited by SelfTaught on Apr 2 2014 05:45pm
Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Apr 2 2014 06:06pm
Quote (SelfTaught @ 2 Apr 2014 18:42)
Not familiar with this language but are you specifying the port # when opening your sockets?

e/ If so, make sure the port is open on your router


If server is on my laptop and a read request from laptop it will workfine. But if I read request from my desktop and server is on my laptop I got timeout error.

And yes TFTP client is active on both pc.
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Apr 2 2014 06:13pm
Quote (eric838 @ Apr 2 2014 04:06pm)
If server is on my laptop and a read request from laptop it will workfine. But if I read request from my desktop and server is on my laptop I got timeout error.

And yes TFTP client is active on both pc.


I'd make sure port 69 is open on your router then.
Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Apr 2 2014 06:25pm
Quote (SelfTaught @ 2 Apr 2014 19:13)
I'd make sure port 69 is open on your router then.


where? btw its a D-Link router
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Apr 2 2014 06:29pm
Quote (eric838 @ Apr 2 2014 04:25pm)
where? btw its a D-Link router


This should help. However, you may need to change the series / model number depending on what dlink router you have.

http://www.dlink.com/uk/en/support/faq/routers/wireless-routers/dkt-series/how-do-i-open-up-ports-to-my-computer-port-forwarding-on-this-router
Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Apr 2 2014 06:39pm
Quote (SelfTaught @ 2 Apr 2014 19:29)
This should help. However, you may need to change the series / model number depending on what dlink router you have.

http://www.dlink.com/uk/en/support/faq/routers/wireless-routers/dkt-series/how-do-i-open-up-ports-to-my-computer-port-forwarding-on-this-router


only use port 69 to get read/request

I send data using a dynamic port @ server
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Apr 2 2014 06:47pm
Quote (eric838 @ Apr 2 2014 04:39pm)
only use port 69 to get read/request

I send data using a dynamic port @ server


Beats me. Don't know a whole lot about TFTP. Thought I'd try to help though.
Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Apr 2 2014 06:52pm
Quote (SelfTaught @ 2 Apr 2014 19:47)
Beats me. Don't know a whole lot about TFTP. Thought I'd try to help though.


np ty dude

so the problem is I recaive data from server but cant respond with a ACK
Go Back To Programming & Development Topic List
12Next
Add Reply New Topic New Poll