Socket 传输问题,各店帮忙看看。 [问题点数:100分,结帖人waterljb]

Bbs2
本版专家分:148
结帖率 97.14%
Bbs2
本版专家分:148
Bbs2
本版专家分:148
Bbs2
本版专家分:148
Bbs2
本版专家分:148
Bbs2
本版专家分:148
Bbs2
本版专家分:148
Bbs2
本版专家分:148
Bbs2
本版专家分:148
Bbs2
本版专家分:148
Bbs2
本版专家分:148
Bbs2
本版专家分:148
socket传输问题
Client端把自定义的Report对象分成多个定长的包发送,在Server端也按同样的定长接收。但接收到包的数量总是大于发送的数量,而且虽然反序列化能成功,但从反序列化所得到的Report对象中的byte[]字段的长度比Client端发送时要长。这个byte[]是用来保存图片的,出现这种情况导致图片不能正常在Server端显示。而且在Report对象中只有这个byte[]的字段出现<em>问题</em>,其他3个String型的字段都没有<em>问题</em>。这个<em>问题</em>当Client端和Server端在同一台计算机上时是不会出现的,应该和网络<em>传输</em>有关,但我不清楚到底是哪里的<em>问题</em>。下面是代码,希望各位高手指点一二。rnrnReport类rn[code=C#]rnpublic class Reportrn rn public string textOne;rn public string textTwo;rn public byte[] pic;rn public string textThree;rn rn[/code]rnrnClient端代码rn[code=C#]rn Socket <em>socket</em> = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);rn IPEndPoint ep = new IPEndPoint(Dns.GetHostEntry("12.23.5.678").AddressList[0], 9999);rnrn <em>socket</em>.Connect(ep);rnrn XmlSerializer xs = new XmlSerializer(typeof(Report));rn StringWriter sw = new StringWriter();rnrn Report report = new Report();rn report.textOne= "qwe";rn report.textTwo= "asd";rn report.textThree= "zxc";rnrn MemoryStream ms = new MemoryStream();rn pic.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);rn report.pic = ms.GetBuffer();rnrn xs.Serialize(sw, report);rn string reportString = sw.GetStringBuilder().ToString();rn byte[] reportBytes = System.Text.Encoding.Default.GetBytes(reportString);rnrn int pos = 0;rn int count = 0;rn while (pos < reportBytes.Length)rn rn byte[] data = new byte[1024];rn if (reportBytes.Length - pos >= 1024)rn rn Array.Copy(reportBytes, pos, data, 0, 1024);rn rn elsern rn Array.Copy(reportBytes, pos, data, 0, reportBytes.Length - pos);rn rn <em>socket</em>.Send(data);rn count++;rn pos += 1024;rn rn <em>socket</em>.Shutdown(SocketShutdown.Both);rn <em>socket</em>.Close();rn[/code]rnrnServer端代码rn[code=C#]rn <em>socket</em> = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);rn ep = new IPEndPoint(Dns.GetHostEntry("12.23.5.678").AddressList[0], 9999);rnrn <em>socket</em>.Bind(ep);rn <em>socket</em>.Listen(100);rnrn Socket client = <em>socket</em>.Accept();rnrn byte[] data = new byte[1024];rnrn MemoryStream ms = new MemoryStream();rn int count = 0;rn while (client.Receive(data) > 0)rn rn count++;rn ms.Write(data, 0, 1024);rn rn Console.Write(count);rnrn string stepOne = System.Text.Encoding.Default.GetString(ms.GetBuffer());rnrn XmlSerializer ser = new XmlSerializer(typeof(Report));rn StringReader sr = new StringReader(stepOne);rn Report report = (Report)ser.Deserialize(sr);rnrn return report;rn[/code]rnrn
socket传输问题
各位哥们,请<em>帮忙</em>:rn我现在在linux下用c语言编写<em>socket</em>通信程序,但是遇到了很多的rn<em>问题</em>。rn我从别的程序中接收到的是浮点数,而且对方是不停的发送的,我怎样rn在c语言中将浮点数转化成二进制或是别的什么形式以便能在<em>socket</em>中进rn行<em>传输</em>。rn怎样在一个程序中建立两个<em>socket</em>通道,一个进行<em>传输</em>数据,一个进行<em>传输</em>rn控制字。rn
socket传输文件流的问题
$instream="E:\\apache\\htdocs\\cartoonwin\\sms\\output\\in.jpg";rn$outstream="http://localhost/cartoonwin/sms/files/out.jpg";rnread_file($outstream,$instream);rnfunction read_file($os,$is)rn $str="";rn $fp=fopen($os,'r');rn while(!feof($fp))rn $str.=fgets($fp,4096);rn rn fclose($fp);rn echo $str;rn if($str)rn $fp=fopen($is,"w");rn fputs($fp,$str);rn fclose($fp);rn rnrnie中执行以上文件后,得到in.jpg,但却无法显示,并不是我想要的out.jpg的备份。rn请教各位大虾如何做才能把out.jpg<em>传输</em>到in.jpgrn(而奇怪的是如果是txt文件的话是可以<em>传输</em>的)
socket传输大小问题
TCP/IP详解上说,以太网数据帧的物理特性是其长度必须在46到1500字节之间,那么用<em>socket</em>编程,采用流式数据<em>传输</em>,一个recv()可否一次传递大于1500字节的数据呢?rn谢谢!两日内给分!
socket大文件传输问题
利用<em>socket</em>进行大文件<em>传输</em>时出现大量延时现象,传了一部分就停顿一下,如此往复。请问高手们如何解决他,我的想法是增加<em>socket</em>缓冲区大小,但不能完全避免。
socket传输问题
如何通过<em>socket</em>把该list结构<em>传输</em>到另一端??
关于socket传输问题
我想做个视频聊天程序.摄像头捕捉已经做好了.rn现在往服务器上传信息,想用<em>socket</em>同时传文字和视频捕捉下来的图片.rn是开两个端口传还是怎么弄,请高手帮<em>帮忙</em>.给个示例
Socket传输问题
我用的是C#的异步<em>传输</em>,但是我发现每次(ReceiveCallBack(IAsyncResult ar))这个回调时,只能得到最多1M的数据,其余数据会直接被切开,这就会导致,数据<em>传输</em>的不完整性,请问有没有人遇到过同样的<em>问题</em>,求问是如何解决的???我现在在做一个服务器端的程序,每次玩家登陆都需要给玩家发送已经在游戏状态的玩家,但是用户数量又大于1M无法<em>传输</em>,而且ar会自动截断数据,导致数据损坏。求大神<em>帮忙</em>哦
Socket传输大文件问题
我用Socket<em>传输</em>大文件,现在是想提高<em>传输</em>速度,多点<em>传输</em>具体是什么意思?rn<em>问题</em>1:是否我Accept一个Socket,然后是在这个Socket基础之上多线程分段Send吗?那接收端怎么办?rn<em>问题</em>2:是否建立多个连接,分段传送?接收端全部收到后排序合并?多个连接怎么建立,需要设置不同的端口?
Java Socket 传输问题
在用Java 做Socket网络通信的时候,会遇到将一个对象<em>传输</em>给客户端,我有2种想法:rnrn1. 将这个对象的成员变量组装成字符串,然后<em>传输</em>出去,客户端接收到字符串后按规则分解,取得各个属性初始化为对象rn2. 将这个对象序列化,直接<em>传输</em>,客户端接收到的也就直接是一个对象了rnrn感觉这2种思想,第二种似乎是少走了一步,但是具体到网络<em>传输</em>这样的环境下,性能,安全,可靠,速度之类的等等因素请各位大侠<em>帮忙</em>,给点意见!先谢了哈
socket 传输问题,十万火急!
本人现用VB写了一个服务器的程序和一个客户端的程序,后因某种原因将客户端改成JAVA版本,发现从JAVA中发送出的信息正常;但VB服务器端接收乱码,望各位 大虾<em>帮忙</em>了。
socket数据包传输问题?
有2台主机,A和B,A现在发送一个文件名给B(通过send函数发送一个数据包),大小之前通知过B,有没有这种可能,在网络环境不好的情况下,B需要2次或者多次接受才能把完整的文件名接收到? <em>socket</em>发送的Buffer,是不是先存在TCP的buffer.并且<em>传输</em>,接收端把这些数据包是不是先接收在一个buffer,然后传给recv的buffer?如果要发送的buffer太大呢,怎么发,怎么接,求高手指点。
socket 传输问题
客服端发送一个对象流:对象包含聊天的一些基本信息 ,现在我想做发送文件的功能,<em>问题</em>是:服务器端的接收线程读取的是普通信息的对象,如下:rnrn[code=java] rnObjectInputStream ois= new ObjectInputStream(s.getInputStream()); rnMessage ms = (Message)ois.readObject();rn[/code]rnrn我该怎么区分普通信息和文件信息呢?rn是该message里加一个文件内容的属性?rn还是新写一个文件信息类,如果新写一个类服务端接收怎么分别这两个类呢?rn
SOCKET传输文件问题
建立SOCKET通讯时!rnrn能否把文件直接以二进制的方式直接传给SERVER端(个人感觉一定可以)?rnrn我现在做的是SERVER端先建立一个空文件!rnCLIENT端打开文件读取文件的内容传递内容给SERVER端!rn感觉这样做虽然也能实现文本文件的传递,但是感觉对一些文件来说有很大的rn局限。所以想能不能直接把二进制数据传递给SERVER端!rnrn如果可以直接传二进制数据,有以下不懂的地方!rn(1)CLIENT端通过什么命令可以直接取得二进制数据?rn(2)CLIENT端传递过来的数据SERVER端怎样处理?rn小弟刚学C语言不久,也是着几天接触的网络编程,希望各位大哥能给予指点。rn
socket传输结构体的问题
我的代码想完成把服务器端当前目录传送到客户端的功能。rn使用<em>socket</em><em>传输</em>目录结构体。rn思路是将结构体中的内容放入bufsend<em>传输</em>recv接收buf数据放入目录结构体。rnrn目录结构体定义(ANSI定义)rn[code=C/C++]struct dirent rnino_t d_ino; /* 索引号 */rnoff_t d_off; /* 下一个偏移量 */rnunsigned short d_reclen; /* 本记录长度 */rnunsigned char d_type; /* 文件类型 */rnchar d_name[256]; /* 文件名 */rn;[/code]rnrn服务器端主要代码rn[code=C/C++]DIR *dir;rn struct dirent *ptr;rn char dirbuf[sizeof(*ptr)];rn if((dir = opendir("./")) == NULL) rn perror("opendir\n");rn exit(1);rn rn while((ptr = readdir(dir)) != NULL) rn memcpy(dirbuf, &ptr, sizeof(*ptr)); rn if((sendBytes = send(clientfd, dirbuf, sizeof(dirbuf), 0)) == -1) rn perror("fail to send dir");rn exit(1); rn rn printf("name:%s\n", ptr->d_name);rn rn closedir(dir);rn[/code]rnrn客户端主要代码rn[code=C/C++] struct dirent *ptr;rn char dirbuf[sizeof(*ptr)];rn printf("current dir on server:\n");rn memset(dirbuf, 0x00, sizeof(dirbuf));rn while(recvBytes = recv(sockfd, dirbuf, sizeof(dirbuf), 0)) rn if(recvBytes == -1) rn printf("faile to receive dir");rn exit(1);rn rn memcpy(&ptr, dirbuf, sizeof(*ptr));rn printf("%s\n", ptr->d_name);rn rn[/code]rnrngdb调试客户端,运行到最后一个打印语句时收到“SIGSEGV“发生Segmentation fault.rn请问这是怎么回事呢?rn我该过dirbuf的大小依然不能正常<em>传输</em>。rnrn网上大多数<em>传输</em>结构体的文章都是struct mydata data形式rn是不是struct dirent *ptr比较特殊呢?
Socket传输问题 谢谢!!!
代码贴出来大家给<em>看看</em>吧rn这是客户端的rn[code=Java] public static List elementMap = new ArrayList();rnrn public static void main(String[] args) rn File file = new File("G:\\Workspace\\InterfaceGZRC\\doc\\TCO1.xml");rn byte[] val = new byte[4690];rnrn BufferedReader in;rn DataOutputStream out;rn try rn InputStream input = new FileInputStream(file);rn input.read(val, 0, val.length);rn for (int i = 0; i < val.length; i++) rn System.out.println((char)val[i]);rn rn Socket <em>socket</em> = new Socket("localhost", 5008);rn in = new BufferedReader(new InputStreamReader(<em>socket</em>rn .getInputStream()));rn out = new DataOutputStream(<em>socket</em>.getOutputStream());rn out.write(val);rnrn catch (UnknownHostException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn catch (IOException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn [/code]rn这是服务端rn[code=Java]rn public void getxml(InputStream in) rn byte[] val = new byte[4690];rn try rn //InputStream in = new FileInputStream(file);rn InputStream inputStream=new DataInputStream(in);rn inputStream.read(val, 0, val.length);rn inputStream.close();rn for (int i = 0; i < val.length; i++) rn System.out.println((char)val[i]);rn rn ByteArrayInputStream bais = new ByteArrayInputStream(val);rn SAXReader saxReader = new SAXReader();rn Document document = saxReader.read(bais);rn Element rootElement = document.getRootElement();rn new Xml_Parse().removePrefix(rootElement);rnrn catch (Exception e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn rn[/code]rn因外一个方法rn[code=Java]private void removePrefix(Element element) rnrn if (element.getData().toString().trim() != nullrn && !element.getData().toString().trim().equals("")) rn elementMap.add(0, ":" + element.getQName().getName() + ":"rn + element.getData().toString());rn rn if (element != null && element.getQName().getName().length() > 0) rn element.setQName(new QName(element.getQName().getName()));rn Iterator elementIterator = element.elementIterator();rn while (elementIterator.hasNext()) rn this.removePrefix((Element) elementIterator.next());rn rn rn[/code]rn大至就是这样的 但是我接收后前四位却没有了rn客户端打印:rn
Socket外网传输问题
本人最近做一个模拟qq的聊天软件,用的是<em>socket</em> tcp协议,遇到了个奇怪的<em>问题</em>,在内网里面进行测试,一切都是正常,后来把服务端放在外网,出现了聊天列表(9KB)加载不出来<em>问题</em>,它是偶尔加载不出来,后来我用线程堵塞了下客户端的接收,堵塞时间为2s,这样加载出来的成功率高了很多,但是任然有加载不出来的时候,客户端和服务端分别写了错误日志。rn 服务端:发送数据错误,断开本连接。Message:System.Object EvalJScriptEx(System.String, System.String, System.String)rnObject reference not set to an instance of an object.rn数据发送失败。rn 客户端:System.IO.IOException: 无法从<em>传输</em>连接中读取数据: 您的主机中的软件中止了一个已建立的连接。。 - System.Net.Sockets.SocketException: 您的主机中的软件中止了一个已建立的连接。rnrn从错误日志中可以看出,是因为<em>socket</em>连接断了,是因为是导致它断开连接的呢?rnrn客户端向服务端发送请求,服务端返回相应信息,为什么会出现这样的情况呢?求大神讲解,急!
Socket批量传输问题
用Socket<em>传输</em>时一次只能传一定的数据,我想将<em>传输</em>的数据放到一个结构体当中,然后分rn批<em>传输</em>,每次1024个字节rnSend:rn CSocket sockRecv;rn DATA Data;rn DWORD dw;rn DWORD dwRead=0;rn while (dwRead
Socket传输大数据的问题
有一个很大的图片数据(921600字节)要使用<em>socket</em>发送给其他用户,<em>socket</em>好像要对数据进行分片,那么我在接收端收到的只是一片的内容,如何协调发送端和接收端的数据传送?
socket 传输文件问题
我用TCP编了个聊天软件,想加入文件<em>传输</em>功能,就是在点击<em>传输</em>文件按钮时,对方能够弹出一个对话框是否同意接受。这个功能怎么样实现呢?小弟一时还想不起来啊,不知那个高手肯给予指点迷津啊?感谢了!!!
socket传输数据结构的问题?????
有一个数据结构,它有两个成员变量,我把它申明成一个类:rnclass Struct rn Byte a[]=new Byte[5];rn Int b;rnrnrn我想把这个结构通过SOCKET的方式发送给服务器?请问:1、我的数据结构的申明有没有<em>问题</em>?2、如果通过SOCKET<em>传输</em>这样的一个结构?rn谢谢!
socket传输图片问题
从服务器端传送一张图片到客户端(这里用的是jpg),奇怪的是有时候传送成功,有时候传送失败.我所用的方法是把图片的字节流传过去,可是无论是分批传还是一次性<em>传输</em>(图片大小在80K左右),<em>问题</em>总是存在.rnrn服务器端主要代码 C++rn// transfer image start with rn inImage.open((dir+filename+".jpg").c_str(),fstream::binary);rn CNetwork::Send(clientSocket,"\n",strlen("\n"));rn int length; // clientSocket 为客户端套接字rn char * buffer;rnrn // get length of file:rn inImage.seekg (0, ios::end);rn length = inImage.tellg();rn inImage.seekg (0, ios::beg);rnrn // allocate memory:rn buffer = new char [length];rnrn // read data as a block:rn inImage.read(buffer,length);rn CNetwork::Send(clientSocket, buffer, length);rn inImage.close();rn delete [] buffer;rn客户端主要代码 Javarn server = new Socket(host,port);rn // get input streamrn InputStream inn = server.getInputStream();rn BufferedReader bufIn = new BufferedReader(new InputStreamReader(inn));rn // get ouput streamrn PrintWriter out = new PrintWriter(server.getOutputStream());rn // send the name of the file which we need to serverrn out.write(filename.toCharArray(),0,filename.length());rn out.flush();rn String line; //rn while ((line = bufIn.readLine()) != null) rn if (line.equals(""))rn fileTransfer(bufIn);rn else if (line.equals(""))rn bufImage = imageTransfer();rn break;rn rnrnpublic BufferedImage imageTransfer() throws IOExceptionrn BufferedImage image=null;rn // get input streamrn ImageInputStream stream = ImageIO.createImageInputStream(rn server.getInputStream());//server为连接的<em>socket</em>rn image = ImageIO.read(stream);rn ImageIO.write(image,"jpg",new File(filename+".jpg"));rn return image;rn
socket传输文件的问题?
最近刚开始学<em>socket</em>编程,看书加上网,也看了不少代码,rn照别人的模式弄了一个C/S结构的,TCP协议的rn服务器端采用的是异步非阻塞WSAAsyncSelect(),客户端用的是阻塞模式,rnrn结果发文件的时候总是服务器端迅速显示发送完毕,而客户端却只接收了一部分数据rn后来在服务器端加了个Sleep(nt),当nt值稍大的时候,<em>传输</em>可以成功。send和recv代码部分:rnrn[code=C/C++]////服务器端rnvoid CServerDlg::OnSend()rn rn if( !( bFileIsOpen = sourceFile.Open( sendfname,CFile::modeRead | CFile::typeBinary, &fe ) ) ) rn rn AfxMessageBox(_T("ERR"));rn CleanUp(); rn rn rn rn //首先传递将要被发送文件的长度给接收端 rn fileLength = sourceFile.GetLength(); rn fileLength = htonl( fileLength );//似乎没有必要,只要两边都不转换也可以吧? rn int nLeftToSend = sizeof( fileLength ); rn int nSent=0; rn do rn rn BYTE* bp = (BYTE*)(&fileLength) + nSent; rn int ns = send(<em>socket</em>send, (const char*)bp, nLeftToSend,0 ); rn rn if ( ns == SOCKET_ERROR ) rn rn AfxMessageBox(_T("ERR"));rn CleanUp(); rn rn nLeftToSend - = ns; rn nSent + = ns; rn rn while ( nLeftToSend>0 ); rn rn rn //开始发送文件数据 rn char* sendData = new char[1024]; rn nLeftToSend = sourceFile.GetLength(); rn rn do rn rn int sendThisTime, doneSoFar, buffOffset; rn rn sendThisTime = sourceFile.Read( sendData, 1024); rn buffOffset = 0; rn do rn rn doneSoFar = send(<em>socket</em>send,(const char*) (sendData + buffOffset),sendThisTime,0 ); rn rn if ( doneSoFar == SOCKET_ERROR ) rn rn AfxMessageBox(_T("ERR"));rn CleanUp(); rn rn buffOffset += doneSoFar; rn sendThisTime -= doneSoFar; rn nLeftToSend -= doneSoFar; rn rn while ( sendThisTime > 0 ); rn Sleep(10);//这是后来我自己加的,有时能起作用 rn rn rn while ( nLeftToSend > 0 ); rnrn ::PostMessage(hwnd,UM_PRGSOVER,0,0);//向主窗口发送消息发送完毕 \ rn CleanUp();rnrnrnrn////客户端rnvoid CClientDlg::OnReceive()rnrn //文件已建立好rnrn //首先接收文件的长度信息 rn nLeftToReceive = sizeof( dataLength ); rn nReceived = 0; rn do rn rn BYTE* bp = (BYTE*)(&dataLength) + nReceived; rn int nr = recv(sockConn, (char*)bp, nLeftToReceive,0); rn rn if ( nr == SOCKET_ERROR || nr == 0 ) rn rn AfxMessageBox(_T("ERR"));rn CleanUp(); rn rn nLeftToReceive - = nr; rn nReceived + = nr; rn rn rn while ( nLeftToReceive > 0 ); rn rn dataLength = ntohl( dataLength ); //将文件的长度信息转化为本地字节序,服务器端是相反转换 rn //准备开始接收文件 rn recdData = new byte[RECV_BUFFER_SIZE]; rn nLeftToReceive = dataLength; rn rn do rn rn int iiGet, iiRecd; rn rn iiGet = (nLeftToReceive 0 ); rn rn ::PostMessage(hwnd,UM_PRGROVER,0,0); //向主窗口发送消息 rn CleanUp(); rn[/code]代码不太完整,主要请大家帮我<em>看看</em>采用的结构和步骤是不是很挫,呵呵rnrn现在请教这么几个<em>问题</em>:rnrn1、收发文件时,同时兼顾速度和成功率,大家一般是怎么处理的?客户端和服务器端采用什么模式较好?rnrn2、还有,我在客户端也想用异步非阻塞模式,可是connect的时候总显示连不上服务器,rn但是服务器端有反应,是怎么回事?rnrn3、<em>socket</em><em>传输</em>到底是什么机制?服务器端执行一次send(),客户端端是不是一定能受到FD_READ消息?rnrn我头都昏了,请大家指教!
socket 传输问题
While sqlrd.Readrn Rstr = "Rs|" & Trim(sqlrd("area")) & "^"rn WriteComm(Rstr, wsk)rn End Whilern 这样发送为什么客户段接受的信息为什么不是一条条信息过去,反而是发送过的信息是多条信息连在了一起发过去,是什么<em>问题</em>,望高手<em>帮忙</em>!!!
关于socket传输问题
我在编一个UDP<em>传输</em>文件的程序,编完后可以<em>传输</em>,但是就是特别慢,每秒大约40k字节rn我用的是多线程,分接受和发送两个线程,我实在找不出速度慢的原因,后来记录时间信息rn发现接受线程接受两个包的间隔在15毫秒,不只为何?请各位大虾指教
帮忙看看这段程序,异步Socket问题
这段代码是MSDN里的异步Socket的例子rn当引用这个类后rn第一次调用main方法可以执行rn第二次调用就出错rn说Socket没有建立连接rn不知道怎么回事?rn请高手<em>帮忙</em><em>看看</em>!rnrn=======================================================rn我的程序调用:rnDim abc as new AsynchronousClientrnabc.main '第一次调用(正常)rnabc.main '第二次调用(出错)rnrnrnrn异步Socket类代码(MSDN):rnrnImports SystemrnImports System.NetrnImports System.Net.SocketsrnImports System.ThreadingrnImports System.Textrnrn' State object for receiving data from remote device.rnPublic Class StateObjectrn Public workSocket As Socket = Nothing ' Client <em>socket</em>.rn Public BufferSize As Integer = 256 ' Size of receive buffer.rn Public buffer(256) As Byte ' Receive buffer.rn Public sb As New StringBuilder() ' Received data string.rnEnd Class 'StateObjectrnrnPublic Class AsynchronousClientrn ' The port number for the remote device.rn Private Shared port As Integer = 11000rn rn ' ManualResetEvent instances signal completion.rn Private Shared connectDone As New ManualResetEvent(False)rn Private Shared sendDone As New ManualResetEvent(False)rn Private Shared receiveDone As New ManualResetEvent(False)rn rn ' The response from the remote device.rn Private Shared response As [String] = [String].Emptyrn rn rn Private Shared Sub StartClient()rn ' Connect to a remote device.rn Tryrn ' Establish the remote endpoint for the <em>socket</em>.rn ' The name of thern ' remote device is "host.contoso.com".rn Dim ipHostInfo As IPHostEntry = Dns.Resolve("host.contoso.com")rn Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)rn Dim remoteEP As New IPEndPoint(ipAddress, port)rn rn ' Create a TCP/IP <em>socket</em>.rn Dim client As New Socket(AddressFamily.InterNetwork, _rn SocketType.Stream, ProtocolType.Tcp)rn rn ' Connect to the remote endpoint.rn client.BeginConnect(remoteEP, AddressOf ConnectCallback, client)rn connectDone.WaitOne()rn rn ' Send test data to the remote device.rn Send(client, "This is a test")rn sendDone.WaitOne()rn rn ' Receive the response from the remote device.rn Receive(client)rn receiveDone.WaitOne()rn rn ' Write the response to the console.rn Console.WriteLine("Response received : 0", response)rn rn ' Release the <em>socket</em>.rn client.Shutdown(SocketShutdown.Both)rn client.Close()rn rn Catch e As Exceptionrn Console.WriteLine(e.ToString())rn End Tryrn End Sub 'StartClientrn rn rn Private Shared Sub ConnectCallback(ar As IAsyncResult)rn Tryrn ' Retrieve the <em>socket</em> from the state object.rn Dim client As Socket = CType(ar.AsyncState, Socket)rn rn ' Complete the connection.rn client.EndConnect(ar)rn rn Console.WriteLine("Socket connected to 0", _rn client.RemoteEndPoint.ToString())rn rn ' Signal that the connection has been made.rn connectDone.Set()rn Catch e As Exceptionrn Console.WriteLine(e.ToString())rn End Tryrn End Sub 'ConnectCallbackrn rn rn Private Shared Sub Receive(client As Socket)rn Tryrn ' Create the state object.rn Dim state As New StateObject()rn state.workSocket = clientrn rn ' Begin receiving the data from the remote device.rn client.BeginReceive(state.buffer, 0, state.BufferSize, 0, _rn AddressOf ReceiveCallback, state)rn Catch e As Exceptionrn Console.WriteLine(e.ToString())rn End Tryrn End Sub 'Receivern rn rn Private Shared Sub ReceiveCallback(ar As IAsyncResult)rn Tryrn ' Retrieve the state object and client <em>socket</em> rn ' from the async state object.rn Dim state As StateObject = CType(ar.AsyncState, StateObject)rn Dim client As Socket = state.workSocketrn rn ' Read data from the remote device.rn Dim bytesRead As Integer = client.EndReceive(ar)rn rn If bytesRead > 0 Thenrn ' There might be more data, so store the data received so far.rn state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, _rn bytesRead))rn rn ' Get the rest of the data.rn client.BeginReceive(state.buffer, 0, state.BufferSize, 0, _rn AddressOf ReceiveCallback, state)rn Elsern ' All the data has arrived; put it in response.rn If state.sb.Length > 1 Thenrn response = state.sb.ToString()rn End Ifrn ' Signal that all bytes have been received.rn receiveDone.Set()rn End Ifrn Catch e As Exceptionrn Console.WriteLine(e.ToString())rn End Tryrn End Sub 'ReceiveCallbackrn rn rn Private Shared Sub Send(client As Socket, data As [String])rn ' Convert the string data to byte data using ASCII encoding.rn Dim byteData As Byte() = Encoding.ASCII.GetBytes(data)rn rn ' Begin sending the data to the remote device.rn client.BeginSend(byteData, 0, byteData.Length, 0, _rn AddressOf SendCallback, client)rn End Sub 'Sendrn rn rn Private Shared Sub SendCallback(ar As IAsyncResult)rn Tryrn ' Retrieve the <em>socket</em> from the state object.rn Dim client As Socket = CType(ar.AsyncState, Socket)rn rn ' Complete sending the data to the remote device.rn Dim bytesSent As Integer = client.EndSend(ar)rn Console.WriteLine("Sent 0 bytes to server.", bytesSent)rn rn ' Signal that all bytes have been sent.rn sendDone.Set()rn Catch e As Exceptionrn Console.WriteLine(e.ToString())rn End Tryrn End Sub 'SendCallbackrn rn 'Entry point that delegates to C-style main Private Function.rn Public Overloads Shared Sub Main()rn System.Environment.ExitCode = _rn Main(System.Environment.GetCommandLineArgs())rn End Subrn rn rn Overloads Public Shared Function Main(args() As [String]) As Integerrn StartClient()rn Return 0rn End Function 'MainrnEnd Class 'AsynchronousClientrn=======================================================rnrn
socket问题,希望大神帮忙看看
摸索一天了,都不知道哪出<em>问题</em>了!以下是程序:rnrnwindow下VS2010写的客户端程序:rn#include rn#include rn#include rn#include rnusing namespace std; rn#pragma comment(lib, "ws2_32.lib ") rn rn rn//0 加载套接字库(WSAStartup())rnbool LoadWSA(); rnrn//1 创建套接字(<em>socket</em>());rnbool CreateSocket(SOCKET& sock,int type=SOCK_STREAM); rnrn//2 向服务器发出连接请求(connect());rnbool ConnectToServer(SOCKET& sock,short port ,const char* strIp); rnrn//3 和服务器端进行通信(send()/recv())rnbool Communicate(SOCKET& sock); rnrn//4 rnbool CloseSocket(SOCKET& sock); rnrn//5 关闭加载的套接字库(WSACleanup())rnvoid CloseWSA(); rn rnvoid ExitWithErrorMessage(const string& errMsg); rn rn rnvoid main() rn rn cout<<<<<<<<<
求大神帮忙看看,php socket问题
[code=php] $appenStr = $buf = '';rn $time = time();rn for($i=0;$i 5)rn break;rn rn if($buf)rn $appenStr .= $buf;rn elsern break;rn rn rn rn echo $appenStr;[/code]rn网上看了很多资料,是<em>socket</em>_read这个函数阻塞了,导致的客户端程序一直假死状态,一直等待上面代码的结果 返回。rn但是我这样就能取出来数据了。rn[code=php]$buf = <em>socket</em>_read($msgsock, 8192);rn $buf .= <em>socket</em>_read($msgsock, 8192);rn $buf .= <em>socket</em>_read($msgsock, 8192);[/code]可是总不能算好字节数去取吧。还有下面的代码我也试过了,还是假死,一直在加载中。[code=php]$appenStr = $out = '';rn $start_time = time();rn dorn if (false === ($out = <em>socket</em>_read($msgsock, 8192)))rn rn echo ("SOCKET_READ_ERROR: " . <em>socket</em>_strerror(<em>socket</em>_last_error($msgsock)));rn $str = "";rn break;rn rn if (time() - $start_time > 1)rn rn echo ("SOCKET_READ_ERROR: Timeout!!!");rn $str = "";rn break;rn rn $appenStr .= $out;rn while ($out != "");[/code]rn求大神指导
帮忙看看socket包装类的问题
请问,对<em>socket</em>进行包装,其中一个方法是接受客户端的连接。以下的两个函数,一个有<em>问题</em>,一个没<em>问题</em>。请<em>帮忙</em><em>看看</em>!rn1、这个函数是没<em>问题</em>的,把对象用引用传进去rnvoid CDGSocket::AcceptClient(CDGSocket &s)rnrn struct sockaddr_in cliAddrTmp;rn int cliAddrSize = sizeof(struct sockaddr_in);rn SOCKET sClient = accept(m_hSocket, (struct sockaddr *)&cliAddrTmp, &cliAddrSize);rn if(sClient == INVALID_SOCKET)rn rn ThrowException("accept() failed!");rn rnrn s.m_hSocket = sClient;rnrnrn客户程序的调用如下:rnCDGSocket sClient;rnsServer.AcceptClient(sClient);rnrn2、这个函数是有<em>问题</em>的rnCDGSocket CDGSocket::AcceptClient()rnrn CDGSocket sClientObj;rn rn struct sockaddr_in cliAddrTmp;rn int cliAddrSize = sizeof(struct sockaddr_in);rn sClientObj.m_hSocket = accept(m_hSocket, (struct sockaddr *)&cliAddrTmp, &cliAddrSize);rn if(sClientObj.m_hSocket == INVALID_SOCKET)rn rn ThrowException("accept() failed!");rn rn rn return sClientObj;rnrn客户程序是这样调用的:rnCDGSocket sClient;rnsClient = sServer.AcceptClient();rn但是就在返回的时候程序出现了异常,我非常迷惑这里是什么原因造成的。rnrn我的拷贝构造函数是这样的,里面没有其他的成员变量,也没有动态开辟的空间。rn按道理来说应该不需要拷贝构造函数。rnCDGSocket::CDGSocket(const CDGSocket &s)rnrn m_hSocket = s.m_hSocket;rnrnrn我自己尝试解决所做的试验:rn1、跟踪出错函数的时候程序是这样跑的:rnreturn sClientObj; 拷贝构造函数--〉析构函数--〉返回--〉出错rnrn开始猜想可能是拷贝构造函数的<em>问题</em>,但是试了一下其他的拷贝内存的方法,也没什么用。rnrn2、查看了MSDN中SOCKET的解释,发现,SOCKET其实就是unsigned int,是一个由Windows分配的句柄值,有点类似于HWND,这种的变量的赋值是否有点特别。rnrn以上这些都是我的疑问,请高手真的<em>帮忙</em><em>看看</em>,自己已经搞了很久。谢谢!!rnrn
帮忙看看socket客户端问题,谢谢!
是这样的,我正在改写一个c在Solaris下写的<em>socket</em>程序,服务器端无法修改,只能自己摸索,改写后的java程序如下,但是运行的时候无论如何也无法取得返回值,因为in.ready()一直都是false,但是<em>socket</em>.isConnected()却一直都是true的。循环中等待了很久也无法取得返回结果。rnrn谢谢各位英雄相助,<em>问题</em>解决一定给分。rnrnpublic class myclass rn rn public static void main(String args[]) rn String xltHost = "132.102.32.2";rn int xltPort = 3001;rn String message;rn String s;rn String line, tt;rn String error;rn //connect to xlt serverrn tryrn Socket <em>socket</em> = new Socket(xltHost, xltPort);rn rn PrintWriter out = new PrintWriter(<em>socket</em>.getOutputStream(), true);rn rn BufferedReader in = new BufferedReader(new InputStreamReader(<em>socket</em>.getInputStream()));rn rn <em>socket</em>.setKeepAlive(true);rn rn /*Send data over <em>socket</em>*/rn s = "Login\r\nEND\r\n"; // 这是我要发送的数据rn out.println(s); rn rn out.flush();rn rn logFile("login send", s);rn rn logFile("isConnected ?", Boolean.toString(<em>socket</em>.isConnected())); //这里得到的是TRUE。rn rn tt = "";rn rn //while ((line = in.readLine()) != null ) rn CharBuffer cb = CharBuffer.allocate(1024);rn while(true)rn logFile("isConnected ?", Boolean.toString(<em>socket</em>.isConnected())); //在循环中这里一直都是true,但是用系统命令netstat -n却看不到两台机器之间有建立连接,怎么回事?rn logFile("ready 1", Boolean.toString(in.ready())); //在循环中这里一直都是false。rn rn //line = in.readLine();rn if (in.ready())rn in.read(cb.array(), 0, cb.length());rn tt = cb.toString();rn rn logFile("line", line);rn if (line != null)rn tt += line + "\r\n";rn rn if (tt.indexOf("END") > 0)rn logFile("end", "i got END");rn break;rn rn logFile("1", "3");rn Thread.sleep(1000);rn logFile("ready 2", Boolean.toString(in.ready()));rn rn elsern Thread.sleep(1000);rn continue;rn rn rn rn rn if (tt.indexOf("Result=0") > 0)rn logFile("login success: ", tt);rn rn elsern logFile("login fail", tt);rn rn logFile("end interface", "");rn return;rn rn //log out from xlt serverrn rn rn catch (IOException e)rn e.printStackTrace();rn error = e.toString();rn System.out.println(error); rn logFile("IOException: ", error);rn System.exit(1);rn rn catch (SecurityException e)rn e.printStackTrace();rn error = e.toString();rn System.out.println(error); rn logFile("SecurityException: ", error);rn System.exit(1);rn rn catch(Exception e)rn e.printStackTrace();rn error = e.toString();rn System.out.println(error);rn logFile("Exception catch:", error);rn rn rn message = ">>>>end>>>>";rn logFile("process end and quit", message);rn logFile("", ""); rn rnrn private static void logFile(String title, String msg)rn rn tryrn rn FileOutputStream out = new FileOutputStream("log.txt",true);rn rn out.write((new String("")).getBytes());rn out.write('\r');rn out.write('\n');rn out.write(msg.getBytes());rn out.write('\r');rn out.write('\n');rn rn out.close();rn rn catch (Exception e)rn rn System.out.println(e.toString());rn rn rn
各位大虾帮忙看看关于Socket的问题????????
能成功 连接和发送数据,,rn但到了接收数据时,,就半天都没反应,,程序又不报错。。。这<em>问题</em>该怎么解决呢??rnrnrnSystem.Net.Sockets.Socket so=new Socket(AddressFamily.InterNetwork,rn SocketType.Stream,rn ProtocolType.Tcp);rn IPAddress hostAddress = Dns.Resolve("202.115.74.100").AddressList[0];rn IPEndPoint ipLocalEndPoint = new IPEndPoint(hostAddress,80);rn so.Connect(ipLocalEndPoint);rn byte[] msg = Encoding.ASCII.GetBytes("This is a test send");rn if(so.Connected)rn rn tryrn rn //发送数据rn int re = int re=so.Send(msg,msg.Length,SocketFlags.None,ipLocalEndPoint);rn if(re>0)rn rn MessageBox.Show("发送成功!!字节数为:"+re.ToString());rn rn IPEndPoint Receive1= new IPEndPoint(IPAddress.None,80);rn EndPoint tempRemoteEP = (EndPoint)Receive1;rn byte[] buffer = new byte[1024];rn //接收数据......??????程序到这里,,就半天都没反应了。rn so.ReceiveFrom(buffer, 0, so.Available, SocketFlags.None,ref tempRemoteEP);rnrn MessageBox.Show("接收数据为:"Encoding.ASCII.GetString(buffer).ToString());rn rn rn catch(Exception ex)rn rn MessageBox.Show("ERORR!!!");rn rnrn rn elsern rn MessageBox.Show("连接失败");rn
win socket接收数据的问题帮忙看看
win <em>socket</em>接收数据的<em>问题</em>,<em>帮忙</em><em>看看</em>。rnrn网络环境:rn1. Server,client 端 均运行在windows系统下,均采用TCP协议,异步方式。rn2. 只有一个client去访问serverrn3. client发送和server接收的频率基本一致,基本不会有client发送多次,server才接收一次的情况。rn4. 为保证数据正确性 client 发送的时候组了个TLV结构的包,包比较小,保证不超过10个字节。rnrn我看见有些人的做法是,先接收 T 和 L 部分,算出L后再用while来循环接收 V 部分。rnrn我的理解:rn1. V 部分比较大的时候采用上述方法是适合的。rn2. 在上述4个条件下,server端待接收的数据比较小, rn  能否在Server端接收的时候开 1K 的 buffer,直接写recv(<em>socket</em>, buf, 1024),rn  然后判断buf中TLV包的有效性,(buf中有可能有多个TLV包)rn 如果判断到TAG非法或包长度不符合期望,则直接认为异常,不需要再recv后续数据了。rnrn请问这种观点正确吗?1和2都评定下哦rnrn
请大家帮忙看看这个Socket问题
private void sendData(Graphics g, boolean b, boolean range) rn Socket coordSocket = null;rn DataOutputStream out = null;rn DataInputStream in = null;rn String info = "";rn try rn String connectto = getCodeBase().getHost();rn coordSocket = new Socket(InetAddress.getByName(connectto), 1080);rn //Initialize the <em>socket</em>, outputstream and inputstream.rn out = new DataOutputStream(coordSocket.getOutputStream());rn in = new DataInputStream(coordSocket.getInputStream());rn //end of tryrn catch(SecurityException e)rn System.out.println("SecurityException when connecting Server!");rn info = e.toString();rn rn catch (UnknownHostException e) rn System.err.println("Don't know about host: taranis.");rn //System.exit(1);rn //end of catchrn catch (IOException e) rn System.err.println("Couldn't get I/O for the connection to: taranis.");rn System.err.println(e.toString());rn //System.exit(1);rn //end of catchrn try rn //转变 Unicode GBrn byte[] bWord = myString.getBytes("GB2312");rn char chWord = (char)((bWord[0]&0xff)|(bWord[1]<< StrokeNum; i++) rn //Number of Pointsrn int StrokeNo = in.readInt();rn int[] X = new int[StrokeNo];rn int[] Y = new int[StrokeNo];rn for (int j = 0; j < StrokeNo; j++) rn X[j] = in.readInt();rn Y[j] = in.readInt();rn //end of for loop inrn //画rn g.fillPolygon(X, Y, StrokeNo);rn try Thread.sleep(600); rn catch (InterruptedException e) rn //end of for loop outrn out.close();rn in.close();rn coordSocket.close();rn //end of ifrn else rn //Send Char to Servletrn out.writeBoolean(range);rn out.flush();rn //-----Receive Every Number of current Strokern StrokeNum = in.readInt();rn //StrokePointCount[0]存储笔画数,其他存储每笔点数rnrnrn写在Applet里面的,Applet运行时会出错,导致tomcat被关闭,请大家<em>帮忙</em>看一下了!谢谢
一个socket问题,请各位帮忙看看
向解决下面的一个<em>问题</em>:rn 有一个服务器,估计在各个时刻处理的客户端用户数目大致固定,但客户不固定。服务器根据从<em>socket</em>收到的数据,来决定这个消息由谁来处理。rn 我想如下解决这个<em>问题</em>: rn 方案一:rn 建立固定数目得线程,主程序接受到消息,转到空闲的线程去处理消息处理程序。 rn方案二:rn 开启固定得线程,让各个线程接收消息并进行处理。rnrn 自己现在比较犹豫的是:rn 如果主程序接收消息,多个客户同时连接,消息会不会丢失。而且,在判断那个线程处于空闲状态方面有没有比较好的算法。rn rn 如果线程接收消息,必须在主程序中建立了一个<em>socket</em>连接后才可以启动线程使用,客户端断开连接后才可以挂起这个线程,用何种方式判断客户端已经断开连接。rn这个线程在这个客户端用完后,怎样不放弃的被其他客户端使用。rn rn 请问这二种方案那个更合理一些,或者请高手给出一个更好的解决办法。rnrn 谢谢各位大虾的指教。小弟入门不久,没有多少份,望指教。如果有类似元码,也请贴出来,参考参考。rn rnrnrn rn
关于socket异步的问题帮忙看看
服务端: private IPEndPoint MyServer;rn private Socket sock;rn private Socket handler;rn private bool bb = true;rnrn private void Form1_Load(object sender, EventArgs e)rn rn tryrn rn MyServer = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 999);rn sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);rn sock.Bind(MyServer);rn sock.Listen(50);rn toolStripStatusLabel1.Text = "开始监听 ...";rn sock.BeginAccept(new AsyncCallback(AcceptCallback), sock);rn rn catch (Exception ee) toolStripStatusLabel1.Text = ee.Message; rnrn Control.CheckForIllegalCrossThreadCalls = false;rn rn rnrn private void targett()rn rn if (handler.Connected)rn rn toolStripStatusLabel1.Text = "与客户建立连接。";rn while (bb)rn rn Byte[] bbb = new Byte[64];rn handler.Receive(bbb, bbb.Length, 0);rn string ccc = System.Text.Encoding.BigEndianUnicode.GetString(bbb);rn string x = "w";rn int i = ccc.IndexOf(x);rn if (i > 0)rn rn saveUser(ccc); rn rn richTextBox1.AppendText(ccc + "\r\n");rn rn rn rn private void saveUser(string str)rn rn ...rn rn private void AcceptCallback(IAsyncResult ar)rn rn toolStripStatusLabel1.Text = "与客户建立连接!";rn handler = ((Socket)ar.AsyncState).EndAccept(ar);rn Thread thread = new Thread(new ThreadStart(targett));rn thread.Start();rn rnrn客户端:rn private IPEndPoint MyServer;rn private Socket sock;rn private bool bb = true;rn rn private void Form1_Load(object sender, EventArgs e)rn rn tryrn rn MyServer = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 999);rn sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);rn sock.Connect(MyServer);rn toolStripStatusLabel1.Text = "连接成功!";rn Thread thread = new Thread(new ThreadStart(targett));rn thread.Start();rn rn catch (Exception ee) MessageBox.Show(ee.Message); rnrn Control.CheckForIllegalCrossThreadCalls = false;rn rn rn private void targett()rn rn while (bb)rn rn Byte[] bbb = new Byte[640];rn sock.Receive(bbb, bbb.Length, 0);rn string aaaaa = System.Text.Encoding.BigEndianUnicode.GetString(bbb);rn richTextBox1.AppendText(aaaaa);rn rn rn rn private void button2_Click(object sender, EventArgs e)rn rn tryrn rn Byte[] bytee = new Byte[640];rn string send = richTextBox2.Text + "\r\n";rn bytee = System.Text.Encoding.BigEndianUnicode.GetBytes(send.ToCharArray());rn sock.Send(bytee, bytee.Length, 0);rn rn catch MessageBox.Show("连接尚未建立! 无法发送!"); rn rnrn我想在客户端发送一串字符到服务端,服务端判断如果字符中有"w",就执行saveUser(),为什么我发送例如"weeeeee"他还是不执行呢,请大家<em>帮忙</em><em>看看</em>代码有什么<em>问题</em>。
一个简单的socket问题 大家帮忙看看
我写了一个简单的用<em>socket</em>通信的程序 可是 在accept函数这里总是过不去 我还如何解决呢?rn SOCKET s=accept(m_hSocket,(LPSOCKADDR)&m_addr,(int*)sizeof(m_addr));这是我的那个函数 rnrn各位大虾 帮<em>帮忙</em>了
socket文件传输问题,高手帮忙看看
我用filestream读写文件,用networkstream发送接收文件,为何接收到的文件和原文件大小不一致呢?而且有时会显示接收到的文件已损坏,这会是什么原因造成的呢?
***********关于Socket的问题,大家都来帮忙看看*************
就是我Socket <em>socket</em>=ServerSocket.accept();rn然后,当我和这个<em>socket</em>对应的客户端<em>socket</em>断线了,我服务器怎么知道?rnrn好像Socket的那些状态判断函数都不能判断出来。rnrnrn谢谢!
帮忙看看两个问题 阻塞模式的 socket
服务端rnrn[code=C/C++]#include rn#include rn#pragma comment(lib,"wsock32.lib")rnusing namespace std;rn#define SERVER_EXIT_OK 0 //服务器正常退出rn#define SERVER_DLL_ERROR 1 //调用Windows <em>socket</em>s DLL失败rn#define SERVER_API_ERROR 2 //调用Windows <em>socket</em>s API失败rn#define SERVERPORT 5555 //服务器TCP端口rn#define MAX_NUM_BUF 64 //缓冲区最大尺寸rnrn//变量rnchar bufRecv[MAX_NUM_BUF];rnchar bufSend[MAX_NUM_BUF];rnSOCKET sServer;rnSOCKET sClient;rnBOOL bConning;rnrnrnint ExitClient(int nExit)rnrn close<em>socket</em>(sServer);rn close<em>socket</em>(sClient);rn WSACleanup();rn return nExit;rnrnrnBOOL SendLine(SOCKET s, char* str)rnrn int retVal = FALSE;rn retVal = send(s,str,sizeof(str),0);rn if(SOCKET_ERROR == retVal)rn rn cout<<
socket接收数据问题,帮忙看看错处.
在客户机上发送:rn this.senderSocket.Send(System.BitConverter.GetBytes((int)16));rnrn服务器上接收:rnrnwhile(true)rnrnint returncount = TempSocket.Receive(buffer);rnrnint type = ResolveByte(buffer, 0, 4);rnrnConsole.WriteLine("type=0",type);rnrnrn int ResolveByte(byte[] p_a,int p_Start,int p_End)rn rn byte[] intbuffer = new byte[p_End-p_Start];rn rn for(int i = p_Start;irnrnrn为何多出一实心箭头在下一行.?????????
socket问题,请朋友们来帮忙看看
public String recvMsg()rn byte[] b = null;rn try rn in=sockClient.getInputStream();rn b = new byte[in.available()];rn in.read(b);rn catch (IOException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn return b.toString();rn rn请问个方法哪有<em>问题</em>吗
帮忙看看socket怎么运行
SOCKET aSocket[1024];rnint SocketCount=0;rnrnwhile(true)rnrn ....//create and bind m_hSocketrn ret=listen(m_hSocket,2);rn aSocket[SocketCount]=accept(m_hSocket,NULL,NULL);rn SocketCount++;rn if(ret==SOCKET_ERROR) continuern elsern rn while(true)rn rn char buff[1024];rn ret=recv(aSocket[SocketCount-1],buff,128,0);rn ....rn rnrnrn如果accept一个<em>socket</em>以后,m_hSocket是不是还在监听?rnrn另:我这是想把这些放在一个线程中,使这个线程能做为<em>socket</em>的服务端,监听端口,对rn每个连到服务端的请求,实现先到先处理,不能马上处理的先保存的套接字到aSocket中,rn(用数组合适吗?),等前面的处理完再对其进行处理。rnrn各位高手帮<em>帮忙</em>,很急的说。谢谢谢谢!!!
socket的编译错误,请帮忙看看
初学<em>socket</em>编程,在一个控制台应用程序中,明明包含了 "winsock.h",可为什么编译会出现这样的错误rnSTime.obj : error LNK2001: unresolved external symbol _connect@12rnSTime.obj : error LNK2001: unresolved external symbol _htons@4rnSTime.obj : error LNK2001: unresolved external symbol _inet_addr@4rnSTime.obj : error LNK2001: unresolved external symbol _<em>socket</em>@12rnSTime.obj : error LNK2001: unresolved external symbol _close<em>socket</em>@4rnSTime.obj : error LNK2001: unresolved external symbol _recv@16
socket 传输
我有一个类,维护一个数组,然后用线程不停的取数组中数据 调用<em>socket</em>接口 发送出去, 现在我在同一个类中,想发送一个数据,当不加到数组中,直接调用<em>socket</em>接口,这样会有<em>问题</em>么,万一后者调用发送时线程也在调用,会出错么?高手指教
socket传输
这个是两台电脑间构成局域网的数据<em>传输</em>的客户端
SOCKET传输
本代码以客户端和服务端为例,用SOCKET实现了文件<em>传输</em>
同事的店常去看看
同事再网上开了个店,欢迎大家常去<em>看看</em>!再这里也祝同事生意兴隆啊!http://shop33743934.taobao.com/  http://photo.163.com/photos/scorpiongao1119/相册
Socket传输
Socket<em>传输</em>实例 初学者专用哦 包括同步和异步两种模式
java的socket与c的socket传输中文问题
java的<em>socket</em><em>传输</em>中文时,应该怎么处理?求接受与发送时的处理方式。rn我试验了,用byte时,接收到的英文正确,但是中文是??rn发送亦是如此。在线结贴。
异步Socket传输文件问题
要<em>传输</em>的是个1M左右的文件rn部分代码:rnrn sClient 是CAsyncSocket的对象rnrn sClient->Create();rn ....//经判断,是正确的返回值rn MessageBox(NULL, "Pop UP!", "", MB_OK);rn ret = sClient->Send(buf, length);//buf有1M左右rn ....rn <em>问题</em>是在"Pop UP!"弹出时,拔掉网线,sClient->Send(buf, length);返回值不是SOCKET_ERROR。rnrn 各位大大,怎样才能正确的判断send的返回值呢?
有关Socket传输二进制文件问题
我用Socket<em>传输</em>二进制文件(如Gif,JPEG图形文件)总是出错,<em>传输</em>后的文件打不开rn 后来发现在用如下代码时rndim strText() as byternOpen strFileName For Binary As #nFilern strText = String(LOF(nFile), " ")rnGet #nFile, , strTextrnClose #nFilernrnstrText得到的内容与源 文件的内容有差异,不知道是什么道理rn望高手指点
关于socket传输文件的问题
试图用c<em>socket</em>进行文件<em>传输</em> <em>传输</em>纯文本文件没有<em>问题</em> 但如果是其他文件(比如图片文件)跟踪后发现打开文件到缓冲区的时候出现了<em>问题</em>rn rn[code=C/C++]rnCFile file;rnfile.Open("文件路径名",CFile::modeRead|CFile::shareDenyWrite);rnbyte *buffer=NULL;rnlong count=file.GetLength();rnfile.Read(buffer,count);[/code]rnrn执行这些语句后发现直到读取数据之前都没有<em>问题</em> 但是读取数据后buffer并没有把文件中的数据全部读取而是只读取了4个字节rn不是很清楚是什么原因导致的 希望大家能够<em>帮忙</em>看一下 谢谢!..
请教socket传输整数的问题?
我是一个新手,想<em>传输</em>一个整数,可怎么也传不过去,各位帮<em>帮忙</em>。rnBYTE byBuffer[256] = 772 ; //772的十六进制为0304rnsend( mySocket, (LPCSTR)byBuffer, 2, 0);rnrn使用网络嗅探工具发现server端接受到的数据十六进制为0400,转换为十进制变为了1024,不知道怎么回事呀?大侠们帮帮我!
socket传输十六进制数的问题?
小弟愚钝,对byte的操作一直不是很了解,只是知道了一点皮毛,有个<em>问题</em>搞了一下午还没搞定。rn具体是这样的,我要进行客户端的编程,server端的数据协议已经是定好的,server端认为收到的数据格式为:rn03 04 rn01 rn01rn00 01 rn00 00 00 02 rn00 00 00 01rn分为上述几段,为了查看方便,每段我用了回车分开,其实有些段根本用不了4位(比如00 00 00 01,只是用1计算得来的),但是为了扩展,占了4位。其中第一段0304为十进制772,我实现了部分代码,但发现总是有<em>问题</em>:rnrn [code=C/C++] BYTE byBuffer[1024] = 0; rnrn //0304rn DWORD dwData = htons(772);rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 2);rnrn //01 rn dwData = 1;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rn //01 rn dwData = 1;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rn rnrn //00 01 rn dwData = 0;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1); rn dwData = 1;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rn rn //00 00 00 02 rn dwData = 0;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rn dwData = 0;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rn dwData = 0;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rn dwData = 2;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rnrn //00 00 00 01rn dwData =0;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rn dwData = 0;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rn dwData = 0;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rn dwData = 1;rn strncat((LPSTR)byBuffer, (LPSTR)&dwData, 1);rn rn send( mySocket, (LPCSTR)byBuffer, 1024, 0);[/code]rn最后发出去的数据为:rn03 04 01 01 01 02 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 (后面省略了很多00)rn其中只有前面(03 04 01 01)这部分是我想要的结果,中间有一部分00没有传过去,不知道怎么搞呢?rn
socket分包无法传输问题
服务端代码:rnint byteread = networkstream(bytes,0,4096);rnstring data = System.Text.Encoding.Unicode.GetString(bytes,0,byteread);rnint num = Convert.ToInt32(data);rnif(num==PacketNum)rnrn //最后一个包rn SendByte(networkstream,filedata,0,filedata.Length);rnrnelsernrn SendByte(networkstream,filedata,4096*(num-1),4096);rnrnrn客户端:rnif(count>PacketNum)rnrn //发送完rn byte[] Allbyte = ms.GetBuffer();rn this.SaveFileData(Allbyte);rnrnelsernrn//告诉服务端继续发第几个包rn this.SendMessage(count.tostring());rnrn大致思路就是一个包发过来,接收在通知发第二个等等,但是每天发了第一个包之后,客户端发送返回信息时程序就结束了,服务端接收不到返回信息就无法继续发送,这是什么<em>问题</em>呢?
socket传输文件结束时的问题
最近写白板程序,碰上一个之前写网盘的时候也遇到了并且没有解决的<em>问题</em>,真的是“不会的都是要补的orz”,这次终于解决了!(我才不要假上传!) 以服务器向客户端<em>传输</em>文件内容为例: //服务器 while((len=fileInputStream.read(b))!=-1){ outputStream.write(b,0,len); outputStream.flush(); } sock...
java socket传输压缩文件问题
我写了个<em>socket</em><em>传输</em>压缩文件的代码,接收之后文件总是比发送方生成的大,发送方生成的压缩文件解压没<em>问题</em>,但是接收的文件解压就解不开,总是报错,rn请高手指点。代码如下:rnclientrn byte[] exportData = getFjInterfaceService().export(comId, saleOrgId,rn crtDate);rn File zf = new File("RetailerOrder" + crtDate + ".Zip");rn ZipOutputStream zipos;rn BufferedInputStream fos = null;rn OutputStream doc = null;rn Socket s = null;rn try rn zipos = new ZipOutputStream(new FileOutputStream(zf));rn zipos.setMethod(ZipOutputStream.DEFLATED); // 设置压缩方法rnrn zipos.putNextEntry(new ZipEntry("RetailerOrder" + crtDatern + ".Order"));// 创建文件rn DataOutputStream data_output = new DataOutputStream(rn new BufferedOutputStream(zipos));rn data_output.write(exportData);rn data_output.flush();rn data_output.close();rn // 读取压缩文件并写入<em>socket</em>流rn s = new Socket(ip, Integer.parseInt(port));rn fos = new BufferedInputStream(new FileInputStream(zf));rn OutputStream netOut = s.getOutputStream();rn doc = new BufferedOutputStream(netOut);rn // 创建文件读取缓冲区rn byte[] head = new byte[4];rn String len = String.valueOf(fos.available());rn head = len.getBytes();rn doc.write(head, 0, 4);rn doc.flush();rn int p = 0;rn byte[] buf = new byte[1024];rn while (fos.read(buf) != (-1)) // 是否读完文件rn log.debug(p++ + "--" + buf);rn doc.write(buf);// 把文件数据写出网络缓冲区rn doc.flush();// 刷新缓冲区把数据写往客户端rn rn doc.close();rn fos.close();rn Message success = new Message("send","发送" +StruObjectFactory.getOrganNameByOrganId(saleOrgId)+ "订单数据成功!");rn messageHandler.addMessage("success", success); rn catch (FileNotFoundException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn catch (IOException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn finally rn try rn if (doc != null)rn doc.close();rnrn if (fos != null)rn fos.close();rnrn if (s != null)rn s.close();rn catch (IOException e) rn e.printStackTrace();rn rn rnserver:rnrn BufferedInputStream bi = null;rn BufferedOutputStream fileOut = null;rn ZipInputStream zipis;rn try rn bi = new BufferedInputStream(s.getInputStream());rn String savePath = "D:\\RetailerOrder200806231520300001.Zip";rn File fs = new File(savePath);rn fileOut = new BufferedOutputStream( new FileOutputStream(fs));rn int bufferSize = 1024;rn byte[] buf = new byte[bufferSize];rn long len = 0;rn byte[] head = new byte[4];rn bi.read(head, 0, 4);rn int i=0;rn while (bi.read(buf) != -1) rn //System.out.println(i+++"--"+buf);rn fileOut.write(buf);rn fileOut.flush();rn rn fileOut.close();rn bi.close();rn/* // 解压缩,读数据rn zipis = new ZipInputStream(new FileInputStream(fs));rn ZipEntry ze;// 压缩内部文件入口rn // System.out.print("----"+zipis.getNextEntry());rn while ((ze = zipis.getNextEntry()) != null) rnrn String file = "D:\\" + ze.getName();// 生成文件绝对路径及文件名rn File newFile = new File(file);rn System.out.println(file);rn newFile.createNewFile();rn BufferedReader data_input = new BufferedReader(rn new InputStreamReader(zipis));// 源rn BufferedWriter fileWriter = new BufferedWriter(rn new OutputStreamWriter(// 目标rn new FileOutputStream(newFile)));rn String str = "";rn while ((str = data_input.readLine()) != null) rn fileWriter.write(str);rn // System.out.println(i+++"---"+str);rn fileWriter.write("\n");rn fileWriter.flush();rn rn fileWriter.flush();rn fileWriter.close();rn // data_input.close();rnrn rn zipis.close();*/rn catch (IOException e) rn System.out.println(e.toString());rn finally rn System.out.println("Closing Connection...\n");rnrn try rn if (bi != null)rn bi.close();rnrn if (fileOut != null)rn fileOut.close();rnrn if (s != null)rn s.close();rn catch (IOException e) rn rn rn rn
socket 点对点传输模式的问题
想问一下。象是局域网的点对点<em>传输</em>,是不是没有真正意义上的客户端把? 我总觉的 两个点即是客户段又是服务期端,不知道这个想法对吗,主要我也没见过点对点的源码,所以对点对点的结构不太清楚,有点模糊,请各位给点意见,大概的讲解一下啊。。。。。。
Socket利用流传输问题
我是Socket初学者,]rn客户端和服务端都定义了输出输入流OutputStream/InputStreamrn我想问一问哪位大吓:服务端是怎么得到客户端的流的?能和我说一下原理吗?rn谢谢!
WAV文件的Socket传输问题
我想把WAV文件通过网线<em>传输</em>的终端上去播放,用的是rn CFile file;rn if(!file.Open(STR,CFile::modeRead|CFile::typeBinary))rn rn MessageBox(_T("打开文件错误,取消发送!"));rn return ;rn rn 。。。。rn UINT nBytesRead=file.Read(sendBuf,1440);rn但读取的数据全是0,除了WAV的格式符外。rn有人说可以用CFile操作多媒体文件的,不知道<em>问题</em>出在哪!rn难道只能用mmino操作多媒体文件吗?请大侠指点。rn
mfc socket传输文件的问题??
从网上找到这一段内容:rn[code=C/C++]发送端: rnint SendFileLength = 0;//保存已经发送的文件的长度 rnwhile (SendFileLength < filelength) rn rnfile.Seek(SendFileLength,CFile::begin); rnsockSenderror = send(SendFileSock,buffer,TempSendLength,0); rnif(SOCKET_ERROR == sockSenderror) rn rnclose<em>socket</em>(SendFileSock); rnreturn 0; rn rnSendFileLength += TempSendLength; rn rnrn接收端: rnint finish=0;//保存receive函数的返回值 rnwhile(true) rn rnfinish = recv(ConnSock,buffer,BUFFERSIZE,0);//开始写入文件,rnif(SOCKET_ERROR == finish) rn rnAfxMessageBox("接收文件错误!"); rnreturn 0; rn rnfile.Write(buffer,finish); //自动就写到文件末尾了 rn rnrn[/code]rnrnrn现在有一个<em>问题</em>: 发送文件时send中有四个要定义的函数,rn请问其中的第二个函数应该如何填写呢?是写文件名还是?它的原理又是怎样的呢?
关于Socket传输对象的问题
使用Socket,进行通讯,我想传送对象;rn问一下,可不可传自定义的对象类型,而不是Vector。rn如果使用Vector,在Client和Server将数据打包和解包时,rn要进行特别的处理吗,我看了一些Source,好像要序列化。rnrn如果谁有Source,给我参考一下,谢谢了
java与c的socket传输问题
java与c通讯,使用了readline函数,发现c的client发送的buf中没有\n换行符时,readline会等待,当client的<em>socket</em>退出时,及该<em>socket</em>的连接断开时,readline会相应传送的信息。请问有没有别的办法解决。rnrnthis.dis_InputStream = new BufferedReader(new InputStreamReader(s.getInputStream()));rndis_InputStream = new DataInputStream(s.getInputStream());rns_InfoReceived = this.dis_InputStream.readLine();
socket传输图片的问题
功能实现:两个Socket建立连接后,rnserver 发送,client 接收。rn然后server向client发送图片,第一张可以正常接受,第二张就不行了。rnrn代码:rn//ser.javarnimport com.sun.image.codec.jpeg.*;rnimport java.io.*;rnimport javax.imageio.*;rnimport java.awt.image.*;rnimport java.net.*;rnimport java.awt.*;rnrnpublic class Ser extends Thread rn rn public Ser() rn rn rn public void run () rn rn try rn rn output = new ByteArrayOutputStream();rn ss = new ServerSocket(2222);rn s = ss.accept();rn os = s.getOutputStream();rn rn bi = ImageIO.read(new File("k08.jpg"));rn param = JPEGCodec.getDefaultJPEGEncodeParam(bi);rn encoder = JPEGCodec.createJPEGEncoder(output, param);rn encoder.encode(bi);rn output.writeTo(os);rn os.flush();rn output.flush();rn rn rn Thread.sleep(1000);rn bi = ImageIO.read(new File("k09.jpg"));rn param = JPEGCodec.getDefaultJPEGEncodeParam(bi);rn encoder = JPEGCodec.createJPEGEncoder(output, param);rn encoder.encode(bi);rn output.writeTo(os);rn os.flush();rn output.flush();rn rn System.out.println("Server thread start.");rn rn catch (Exception ex) rn ex.printStackTrace();rn rn rn try rn rn os.close();rn encoder.getOutputStream().close();rn rn catch (Exception ex) rn ex.printStackTrace();rn rn rn rn rn public static void main(String[] args) throws Exception rn rn new Ser().start();rn rn rn private BufferedImage bi = null;rn private ServerSocket ss = null;rn private Socket s = null;rn private OutputStream os = null;rn private ByteArrayOutputStream output = null;rn private JPEGEncodeParam param = null;rn private JPEGImageEncoder encoder = null;rnrnrnrn//Cli.javarnimport com.sun.image.codec.jpeg.*;rnimport java.io.*;rnimport javax.imageio.*;rnimport java.awt.image.*;rnimport java.net.*;rnimport java.awt.*;rnimport javax.swing.*;rnrnclass MyFrame extends JFrame rn private MyPanel panel = null; rn public MyFrame() rn panel = new MyPanel();rn add(panel);rn rn rn public void drawScr(BufferedImage bi) rn panel.draw(bi);rn rn rn private class MyPanel extends JPanel rn rn protected void paintComponent(Graphics g) rn super.paintComponent(g);rn g.drawImage(bi, 0, 0, null);rn rn rn public void draw(BufferedImage bi) rn this.bi = bi;rn this.updateUI();rn rn rn private BufferedImage bi = null; rn rnrnrnpublic class Cli extends Thread rn rn public Cli() rn try rn //ip = InetAddress.getByName("10.100.101.36");rn ip = InetAddress.getLocalHost();rn s = new Socket(ip, 2222);rn is = s.getInputStream();rn rn catch (Exception ex) rn ex.printStackTrace();rn System.err.println("public Client.");rn rn rn rn public void run() rn frame = new MyFrame();rn frame.setSize(500, 300);rn frame.setVisible(true);rn frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);rn rn try rn rn rn JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(is);rn BufferedImage bi = decoder.decodeAsBufferedImage();rn if (bi != null) rn rn frame.drawScr(bi);rn System.out.println("drawScr.");rn rn rn rn Thread.sleep(3000);rn decoder = JPEGCodec.createJPEGDecoder(is);rn bi = decoder.decodeAsBufferedImage();rn if (bi != null) rn rn frame.drawScr(bi);rn System.out.println("drawScr.");rn rn rn catch (Exception ex) rn ex.printStackTrace();rn rn rn rn rn public static void main(String[] args) throws Exception rn new Cli().start();rn rnrn private InetAddress ip = null;rn private Socket s = null;rn private InputStream is = null;rn private MyFrame frame = null; rn
socket(TCP)传输文件的问题
我想实现服务器端向多个客户端发送文件和多个客户端向服务器端发送文件的功能。rnrn现在是我的多个客户端都已经连到服务器端,服务器端文件夹里面的文件改变。但是只能同时把文件发送到一个客户端。rnrn怎样才能实现服务器端文件夹里面的文件一但改变,其他客户端都能收到文件?有没有可以参考的源码?rn
socket传输二进制数据流的问题
原来使用普通文件流<em>传输</em>:rnbytes = one.Read(in_read,0,1024);rnstrSend = Encoding.ASCII.GetString(in_read);rnin_read = Encoding.ASCII.GetBytes(strSend);rnclientSocket.BeginSend(in_read,0,bytes,0,new AsyncCallback(SendCallBack),clientSocket);rnrn现在想改成以二进制形式<em>传输</em>,接收端也以二进制形式接收,请问如何做,我手里没有帮助,请稍微解释一下,谢谢。
socket传输问题,请教高手!!
情况是这样的.rn一服务器,一客户端,rn客户端发送一个结构,请求下载.rn服务端接受到结构,判断标志,send要下载的数据.rnrn<em>问题</em>是,每当服务端发送20012个字节时,客户端只能接受8760个字节.数据为什么会丢失?rn我所使用的是流式套接字.两边的数据结构定义的都是一样的.buff的大小也都是一样的.rn
【求助!】Socket传输文件的问题!!!!!!!
如何用<em>socket</em>实现文件的<em>传输</em>?要求接受源文件的地址和目的文件的地址,返回一个bool值表示文件<em>传输</em>是否成功,各位达人帮<em>帮忙</em>~急啊~~快出人命了!!!!
请教:关于SOCKET的传输问题
我的程序是个简单的HTTP服务器,客户端是浏览器。rnrn rn几个FRAME页中有一个页面与我的程序的连接是不断开的。当我关掉浏览器,再打开浏览器,连接到我的程序,就会出现错误对话框:rnrnRuntime Error!rnProgram: E:\HttpServer\HttpServer.exernabnormal program termination.rnrn奇怪的是,我的程序依然还可以正常运行,正常处理其它的HTTP请求。只要不去理会这个错误对话框,一切都正常。<em>问题</em>是每关掉一个浏览器窗口,我的服务器就多一个对话框,烦不胜烦。rnrnCArchive arOut(&<em>socket</em>File,CArchive::store);rnwhile(true)rnrn arOut.WriteString(strPost); //向浏览器输出新内容rn //然后线程挂起,等待主线程唤醒rnrnrn注释掉arOut.WriteString(strPost);这一句后,就永不出现错误对话框。rn我想<em>问题</em>是出在arOut不知道客户端已关闭了连接,所以发送时出错。rn要命的是我用TRY也CATCH不到这个错误!catch(CException *e) does no work!rnrn高手们,怎么办呢?
用SOCKET传输数据结构的问题????
有一个数据结构,它有两个成员变量,我把它申明成一个类:rnclass Struct rn Byte a[]=new Byte[5];rn Int b;rnrnrn我想把这个结构通过SOCKET的方式发送给服务器?请问:1、我的数据结构的申明有没有<em>问题</em>?2、如果通过SOCKET<em>传输</em>这样的一个结构?rn谢谢!
Socket跨网段传输问题
最近考虑架设一个类似于QQ的聊天软件,服务器部署在互联网上,cs架构。rnrn用户与用户间聊天的时候如果不走服务器,就意味着其中一个用户充当client,另外一个用户充当server,但二者不在同一个局域网,client该如何链接server呢?
利用SOCKET传输文件的问题
我写了一个文件<em>传输</em>的小软件,利用WinSock进行文件的<em>传输</em>。但有一些<em>问题</em>,代码如下:rnrn服务器端:rn[code=C/C++]rn//发送文件rnDWORD dwRead;rnBOOL bOk;rnchar sendbuf[1024*4]; //每次传送4KB数据rnrnHANDLE hFile=CreateFile(strFileName,GENERIC_READ,0,0,OPEN_EXISTING,rn FILE_ATTRIBUTE_NORMAL,0);//创建文件句柄rnwhile(1)rnrn ZeroMemory(sendbuf,1024*4);rn bOk=ReadFile(hFile,sendbuf,1024*4,&dwRead,NULL);//读取文件rn if(bOk==FALSE)rn rn break;rn rn else if(dwRead==0)rn rn AfxMessageBox("文件发送完毕");rn break;rn rn elsern rn int nSend=::send(<em>socket</em>,sendbuf,dwRead,0);rn if(nSend));rnCloseHandle(hFile);rn[/code]rnrnrn<em>问题</em>主要是在客户端中的while循环不会跳出来,也就是不会弹出文件下载完成的对话框!但服务器端会提示文件传送完毕,比知道原因何在?rn注:上述代码都在线程使用,其中MessageBox函数是我刚才修改的,方便大家阅读!
关于socket传输问题
有一个<em>问题</em>一直不太明白,我想写一个客户端通过<em>socket</em>流向服务端<em>传输</em>文件的程序。 我想先<em>传输</em>文件名,文件长度,再<em>传输</em>文件内容。可是如果在客户端向流中依次写入这三个部分,那么服务端如何在流中区分开文件名,文件长度和文件内容?
关于异步Socket传输问题
rn 在CAsyncSock类中,当注册AsyncSelect(FD_WRITE)通知时,应该触发rnCAsyncSock::OnSend()消息,然后在OnSend()消息体里处理发送数据rn但在我的应用程序里却触发不了这个消息rn 请问哪位大虾遇到此类<em>问题</em>,是什么原因造成的,应怎样解决呢?
Socket 传输 大数据包的 问题….
请大家<em>帮忙</em>分析一下Socket <em>传输</em> 大数据包的 <em>问题</em>….rnrnSocket Client 发送方法DataOutputStream.write(String.getBytes()) //Buf 为 String.rnSocket server 接收方法:DataInputStream. read(buf[], <em>socket</em>BufferSize*iLoop, readSize)rnSocket 接收,先读取包头,包头里填有数据包长度,bodylengthrn 如果bodylength > <em>socket</em>BufferSize 则分多次读取。 rn在Windows XP Professional, 平台上。Socket.sendBufferSize = 8Krn3K, 7K 22K 发送接收都没有<em>问题</em>rnrn将Socket Server 程度发布到 Sun solaris 10 服务器上后。( Socket.ReceiveBufferSize > 32K )rn测试数据包,3K, 7K,但数据超过8K 就不能接收。rnrn
c++ socket传输中文问题
环境是linux下,IDE为codeblocks,客户端使用flex来接受并显示rn我的服务端在建立了tcp连接之后,用send(fd,"大家阿斯科利多久啊是快乐",SIZE,0)之后,客户端成功收到,但是是乱码rn我改成send(fd,L"大家阿斯科利多久啊是快乐",SIZE,0)双字节处理之后也还是不行,rnc++新人,查了好多资料都无果...
socket tcp 传输文件的问题
[code=C/C++]rn//server接收端rn//其它代码略rn char szbuff[2048];rn memset(szbuff,0,2048);rn FILE *fp = fopen("C:\\qqsetup.exe","wb+");rnrn while(recv(AcceptSocket,szbuff,sizeof(szbuff),0) > 0)rn rn fwrite(szbuff,sizeof(szbuff),1,fp);rn fflush(fp);rn rn fclose(fp);rnrnrn//client发送端rnFILE *pf = fopen("D:\\Applications\\3.0\\3.0\\Vip\\ManageVIP.exe","rb");rnrn char buffer[2048];rn memset(buffer,0,2048);rn while(fread(buffer,sizeof(buffer),1,pf) > 0)rn rn if(send(ConnectSocket,buffer,sizeof(buffer),0) == SOCKET_ERROR)rn rn printf("send error!");rn rn //Sleep(1);rn memset(buffer,0,2048);rn rn fclose(pf);rn[/code]rn为什么send函数运行没有出错,但接收到的文件和原来的文件大小总是有差别,导致不能运行。rn为什么加上了sleep(1)程序就会阻塞,
Fundamentals of Computer Graphics 3rd Edition下载
Publication Date: July 21, 2009 | ISBN-10: 1568814690 | ISBN-13: 978-1568814698 | Edition: 3 With contributions by Michael Ashikhmin, Michael Gleicher, Naty Hoffman, Garrett Johnson, Tamara Munzner, Erik Reinhard, Kelvin Sung, William B. Thompson, Peter Willemsen, Brian Wyvill. The third edition o 相关下载链接:[url=//download.csdn.net/download/ndsc1008/5529985?utm_source=bbsseo]//download.csdn.net/download/ndsc1008/5529985?utm_source=bbsseo[/url]
nLite基础知识教程下载
时下,给系统瘦身已经是许多朋友的热门话题,因为很多人的计算机配置升级了,但还是感觉操作系统的运行没有达到理想的效果。有一种选择:精简系统!当给系统瘦身后,你的爱机将抛弃身上那一层无用的“盔甲”轻装上阵,这样与以前相比,“跑”起来自然会更加轻松流畅! 一般情况下,常规的系统瘦身都是等系统安装好后才对系统进行瘦身操作,但是nLite提供了另一种解决方案:先瘦身,再安装。这样不仅大大节约系统的安装时间,而且也达到了给系统瘦身的目的,这可谓是一举两得的事情!当然,nLite的功能远不止如此,很多很有个性的功能留给用户慢慢体验吧!nLite具有非常强的易用性,一般初级用户根据向导内容即可进行瘦身、优化 相关下载链接:[url=//download.csdn.net/download/qianlixunyin/3033811?utm_source=bbsseo]//download.csdn.net/download/qianlixunyin/3033811?utm_source=bbsseo[/url]
百度影音安装包下载
百度影音基于百度开放平台开发的影视软件支持绝大多数网站很强大 很暴力的哦 相关下载链接:[url=//download.csdn.net/download/gulang3/4948569?utm_source=bbsseo]//download.csdn.net/download/gulang3/4948569?utm_source=bbsseo[/url]
相关热词 c#串口测试应用程序 c# 匹配 正则表达式 c#防止窗体重绘 c#读写txt文件 c#挖地雷源代码 c#弹框选项 c# 移除 队列 c# 密码写入配置文件 c# 获取可用内存大小 c# 嵌入excel编辑
我们是很有底线的